codex-copilot-dx 1.4.21 → 1.4.23
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 +9 -5
- package/docs/ARCHITECTURE.md +7 -1
- package/docs/REFERENCE.md +9 -5
- package/package.json +1 -1
- package/src/adapter.mjs +1 -0
- package/src/antigravity-chat-bridge.mjs +10 -3
- package/src/antigravity-runtime.mjs +8 -5
- package/src/application-control.mjs +14 -7
- package/src/application-process.mjs +9 -4
- package/src/bark-notifications.mjs +18 -7
- package/src/chat-output-parts.mjs +20 -0
- package/src/claude-gateway.mjs +20 -0
- package/src/client-versions.mjs +8 -4
- package/src/dashboard/applications.js +2 -2
- package/src/dashboard/connections-loader.js +36 -0
- package/src/dashboard/connections.js +1 -2
- package/src/dashboard/console.js +4 -2
- package/src/dashboard/gemini.js +81 -34
- package/src/dashboard/index.html +3 -2
- package/src/dashboard/language.js +2 -0
- package/src/dashboard/status.js +5 -1
- package/src/dashboard/tool-activity-arm.js +450 -0
- package/src/dashboard/tool-activity-warehouse.js +352 -0
- package/src/dashboard/tool-activity.js +24 -10
- package/src/dashboard/ui.css +1 -0
- package/src/dashboard/ui.js +45 -4
- package/src/dashboard-assets.mjs +39 -0
- package/src/dashboard.mjs +30 -47
- package/src/gemini-app.mjs +18 -7
- package/src/optional-routes.mjs +3 -3
- package/src/responses-bridge.mjs +37 -7
- package/src/shutdown.mjs +5 -2
- package/src/windows-antigravity-app.mjs +111 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
"use strict";
|
|
3
|
+
const d=Math.SQRT1_2,tau=2*Math.PI,Z=[0,0,1],X=[1,0,0],Y=[0,1,0],camera=[.5,.5,d];
|
|
4
|
+
const limit=(n,a,b)=>Math.max(a,Math.min(n,b));
|
|
5
|
+
const mix=(a,b,t)=>a+(b-a)*t;
|
|
6
|
+
const project=([x,y,z])=>[(x-y)*d,(x+y)*.5-z*d];
|
|
7
|
+
const depth=([x,y,z])=>(x+y)*.5+z*d;
|
|
8
|
+
const dot=(a,b)=>a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
|
|
9
|
+
const plus=(a,b)=>[a[0]+b[0],a[1]+b[1],a[2]+b[2]];
|
|
10
|
+
const scale=(a,s)=>a.map(n=>n*s);
|
|
11
|
+
const identity=p=>p;
|
|
12
|
+
function placement([x,y],angle,z=0) {
|
|
13
|
+
const c=Math.cos(angle),s=Math.sin(angle);
|
|
14
|
+
return ([u,v,w])=>[x+c*u-s*v,y+s*u+c*v,z+w];
|
|
15
|
+
}
|
|
16
|
+
const floor=4,palletBottom=13.2,lo=11.25,hi=18.6;
|
|
17
|
+
const [aisleX,aisleY]=[162,112];
|
|
18
|
+
const distance=(a,b)=>Math.hypot(a[0]-b[0],a[1]-b[1]);
|
|
19
|
+
const jobs=[
|
|
20
|
+
{kind:"cartons",name:"纸箱托盘",home:[19,aisleY],from:[54,aisleY],stop:[108,aisleY],
|
|
21
|
+
through:[[219,aisleY]],delivery:[[270,aisleY],[270,157]],park:[270,197],start:0,color:"amber"},
|
|
22
|
+
{kind:"totes",name:"周转箱托盘",home:[aisleX,209],from:[aisleX,184],stop:[aisleX,163],
|
|
23
|
+
through:[[aisleX,61]],delivery:[[81,61]],park:[34,61],start:.55,color:"sage"},
|
|
24
|
+
{kind:"crate",name:"木箱托盘",home:[304,61],from:[270,61],stop:[216,61],
|
|
25
|
+
through:[[aisleX,61],[aisleX,176]],delivery:[[64,176]],park:[24,176],start:1.1,color:"edge"},
|
|
26
|
+
];
|
|
27
|
+
const direction=(a,b)=>Math.atan2(b[1]-a[1],b[0]-a[0]);
|
|
28
|
+
function timedPath(initial,waypoints,start,speed) {
|
|
29
|
+
const legs=[];
|
|
30
|
+
let pose=initial,time=start;
|
|
31
|
+
function addLeg(next,duration) {
|
|
32
|
+
legs.push({from:pose,to:next,start:time,end:time+duration});
|
|
33
|
+
time+=duration;pose=next;
|
|
34
|
+
}
|
|
35
|
+
for(const point of waypoints) {
|
|
36
|
+
const length=distance(pose.point,point);
|
|
37
|
+
if(!length)continue;
|
|
38
|
+
const delta=direction(pose.point,point)-pose.heading;
|
|
39
|
+
const turn=Math.atan2(Math.sin(delta),Math.cos(delta));
|
|
40
|
+
if(Math.abs(turn)>1e-6)addLeg({...pose,heading:pose.heading+turn,rotation:pose.rotation+turn},.88*Math.abs(turn)/(Math.PI/2));
|
|
41
|
+
addLeg({...pose,point,travel:pose.travel+length},.24+length/speed);
|
|
42
|
+
}
|
|
43
|
+
return {initial,legs,final:pose,end:time};
|
|
44
|
+
}
|
|
45
|
+
for(const j of jobs) {
|
|
46
|
+
const parked={point:j.home,heading:direction(j.home,j.from),travel:0,rotation:0};
|
|
47
|
+
j.pickup=timedPath(parked,[j.from],j.start,24);
|
|
48
|
+
j.dock=j.pickup.end;
|
|
49
|
+
j.liftEnd=j.dock+1.05;
|
|
50
|
+
j.leave=j.liftEnd+.40;
|
|
51
|
+
j.approach=timedPath(j.pickup.final,[j.stop],j.leave,27);
|
|
52
|
+
j.waitSince=j.approach.end;
|
|
53
|
+
}
|
|
54
|
+
let available=0;
|
|
55
|
+
for(const j of [...jobs].sort((a,b)=>a.waitSince-b.waitSince)) {
|
|
56
|
+
j.entry=Math.max(j.waitSince,available);
|
|
57
|
+
j.crossing=timedPath(j.approach.final,j.through,j.entry,37);
|
|
58
|
+
j.exit=j.crossing.end;
|
|
59
|
+
available=j.exit+.48;
|
|
60
|
+
j.outbound=timedPath(j.crossing.final,j.delivery,j.exit,25);
|
|
61
|
+
j.arrive=j.outbound.end;
|
|
62
|
+
j.lowerEnd=j.arrive+1.10;
|
|
63
|
+
j.release=j.lowerEnd+.32;
|
|
64
|
+
j.depart=timedPath(j.outbound.final,[j.park],j.release,24);
|
|
65
|
+
j.done=j.depart.end;
|
|
66
|
+
j.route=[j.home,j.from,j.stop,...j.through,...j.delivery,j.park];
|
|
67
|
+
}
|
|
68
|
+
const total=Math.ceil((Math.max(...jobs.map(j=>j.done))+.4)*50)/50;
|
|
69
|
+
let queue=[];
|
|
70
|
+
|
|
71
|
+
function polygon(vertices, fill=null, edge=null, width=.46, bias=0) {
|
|
72
|
+
queue.push({p:vertices,fill,edge,width,depth:vertices.reduce((n,v)=>n+depth(v),0)/vertices.length+bias});
|
|
73
|
+
}
|
|
74
|
+
function line(a,b,ink="fine",width=.45,bias=.2) {polygon([a,b],null,ink,width,bias);}
|
|
75
|
+
const rect=(x,y,w,h)=>[[x,y],[x+w,y],[x+w,y+h],[x,y+h]];
|
|
76
|
+
function slab(points,z0,z1,top="steel",side="joint",tr=identity) {
|
|
77
|
+
const a=points.map(([x,y])=>tr([x,y,z0])),b=points.map(([x,y])=>tr([x,y,z1]));
|
|
78
|
+
for(let i=0;i<a.length;i++){
|
|
79
|
+
const j=(i+1)%a.length,dx=a[j][0]-a[i][0],dy=a[j][1]-a[i][1];
|
|
80
|
+
if(dy-dx>0)polygon([a[i],a[j],b[j],b[i]],side,"edge",.5);
|
|
81
|
+
}
|
|
82
|
+
polygon(b,top,"edge",.58);
|
|
83
|
+
}
|
|
84
|
+
function box(x,y,z,w,h,v,top="steel",side="joint",tr=identity) {
|
|
85
|
+
slab(rect(x,y,w,h),z,z+v,top,side,tr);
|
|
86
|
+
}
|
|
87
|
+
function flat(x,y,z,w,h,color,tr=identity) {polygon(rect(x,y,w,h).map(([x,y])=>tr([x,y,z])),color,null);}
|
|
88
|
+
function ring(origin,u,v,r,n=18,angle=0) {
|
|
89
|
+
return Array.from({length:n},(_,i)=>plus(origin,plus(scale(u,r*Math.cos(angle+i*tau/n)),scale(v,r*Math.sin(angle+i*tau/n)))));
|
|
90
|
+
}
|
|
91
|
+
function disk(origin,u,v,r,fill="steel",ink="edge",bias=.2) {polygon(ring(origin,u,v,r),fill,ink,.43,bias);}
|
|
92
|
+
function cylinder(a,b,u,v,r,fill="steel",n=16){
|
|
93
|
+
const left=ring(a,u,v,r,n),right=ring(b,u,v,r,n);
|
|
94
|
+
for(let i=0;i<n;i++){
|
|
95
|
+
const j=(i+1)%n,angle=(i+.5)*tau/n;
|
|
96
|
+
if(dot(plus(scale(u,Math.cos(angle)),scale(v,Math.sin(angle))),camera)>0)
|
|
97
|
+
polygon([left[i],left[j],right[j],right[i]],i%3===0?"joint":fill,null);
|
|
98
|
+
}
|
|
99
|
+
const facing=depth(b)>depth(a);
|
|
100
|
+
disk(facing?b:a,u,v,r,fill);
|
|
101
|
+
}
|
|
102
|
+
function bolt(x,y,z,r=1.1,tr=identity){
|
|
103
|
+
polygon(ring([x,y,z],X,Y,r,6,Math.PI/6).map(tr),"joint","edge",.37,.4);
|
|
104
|
+
line(tr([x-r*.55,y,z]),tr([x+r*.55,y,z]),"edge",.36,.51);
|
|
105
|
+
}
|
|
106
|
+
function stopLine(job,color="fine",width=.66){
|
|
107
|
+
const tr=placement(job.stop,job.approach.final.heading);
|
|
108
|
+
for(const across of [-14,-6,2,10])
|
|
109
|
+
line(tr([16,across,4.23]),tr([16,across+4,4.23]),color,width);
|
|
110
|
+
}
|
|
111
|
+
function routeDashes(){
|
|
112
|
+
const lanes=new Map();
|
|
113
|
+
for(const job of jobs)for(let i=1;i<job.route.length;i++){
|
|
114
|
+
const a=job.route[i-1],b=job.route[i],along=a[1]===b[1]?0:1;
|
|
115
|
+
const fixed=a[1-along],key=along+":"+fixed;
|
|
116
|
+
if(!lanes.has(key))lanes.set(key,{along,fixed,segments:[]});
|
|
117
|
+
lanes.get(key).segments.push([Math.min(a[along],b[along]),Math.max(a[along],b[along])]);
|
|
118
|
+
}
|
|
119
|
+
for(const {along,fixed,segments} of lanes.values()){
|
|
120
|
+
segments.sort((a,b)=>a[0]-b[0]);
|
|
121
|
+
const joined=[];
|
|
122
|
+
for(const span of segments){
|
|
123
|
+
const previous=joined.at(-1);
|
|
124
|
+
if(previous&&previous[1]>=span[0])previous[1]=Math.max(previous[1],span[1]);
|
|
125
|
+
else joined.push(span.slice());
|
|
126
|
+
}
|
|
127
|
+
const point=n=>along?[fixed,n,4.13]:[n,fixed,4.13];
|
|
128
|
+
for(const [begin,end] of joined){
|
|
129
|
+
for(let n=Math.ceil(begin/10)*10;n+5<=end;n+=10)line(point(n),point(n+5),"fine",.58);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function platform() {
|
|
134
|
+
const outline=[[7,0],[319,0],[326,7],[326,218],[319,225],[7,225],[0,218],[0,7]];
|
|
135
|
+
slab(outline,0,floor,"floor","joint");
|
|
136
|
+
routeDashes();
|
|
137
|
+
for(const job of jobs)stopLine(job);
|
|
138
|
+
for(const [x,y] of [[9,9],[316,9],[9,215],[316,215]])bolt(x,y,4.12,1.9);
|
|
139
|
+
}
|
|
140
|
+
function shippingBox(x,y,z,w,h,v,material,tr=identity){
|
|
141
|
+
box(x,y,z,w,h,v,material==="crate"?"wood":"kraft",material==="crate"?"kraft":"wood",tr);
|
|
142
|
+
flat(x+w*.43,y+.4,z+v+.08,w*.13,h-.8,"tape",tr);
|
|
143
|
+
line(tr([x+w*.62,y+.5,z+v+.13]),tr([x+w*.62,y+h-.5,z+v+.13]),"fine",.32);
|
|
144
|
+
const yFace=y+h+.07;
|
|
145
|
+
polygon([[x+2.4,yFace,z+v-2.1],[x+8.5,yFace,z+v-2.1],[x+8.5,yFace,z+v-5.4],[x+2.4,yFace,z+v-5.4]].map(tr),"paper-label",null,.3,.22);
|
|
146
|
+
for(let j=0;j<5;j++)line(tr([x+3+j*.93,yFace+.04,z+v-4.65]),tr([x+3+j*.93,yFace+.04,z+v-2.9]),"edge",.27,.24);
|
|
147
|
+
if(material==="crate"){
|
|
148
|
+
for(const r of [1.2,v-1.9]){
|
|
149
|
+
line(tr([x+.5,yFace,z+r]),tr([x+w-.5,yFace,z+r]),"edge",.55,.28);
|
|
150
|
+
line(tr([x+w+.09,y+.4,z+r]),tr([x+w+.09,y+h-.4,z+r]),"edge",.55,.28);
|
|
151
|
+
}
|
|
152
|
+
line(tr([x+1,yFace,z+1.5]),tr([x+w-1,yFace,z+v-1.8]),"fine",.75,.27);
|
|
153
|
+
}
|
|
154
|
+
if(w>12)line(tr([x+w-4,yFace,z+2.1]),tr([x+w-1.7,yFace,z+2.1]),"edge",.37,.3);
|
|
155
|
+
}
|
|
156
|
+
function tote(x,y,z,w,h,v,tr=identity) {
|
|
157
|
+
box(x,y,z,w,h,v,"tote","steel",tr);
|
|
158
|
+
box(x-.75,y-.75,z+v-1.5,w+1.5,h+1.5,1.8,"tote","steel",tr);
|
|
159
|
+
for(let i=2.5;i<w-1;i+=3.4)
|
|
160
|
+
line(tr([x+i,y+h+.08,z+1]),tr([x+i,y+h+.08,z+v-2.1]),"fine",.52,.25);
|
|
161
|
+
for(let i=2.5;i<h-1;i+=3.4)
|
|
162
|
+
line(tr([x+w+.08,y+i,z+1]),tr([x+w+.08,y+i,z+v-2.1]),"fine",.52,.25);
|
|
163
|
+
line(tr([x+w*.36,y+h*.6,z+v+.36]),tr([x+w*.63,y+h*.6,z+v+.36]),"sage",.88,.3);
|
|
164
|
+
}
|
|
165
|
+
function rack(x,y,bays) {
|
|
166
|
+
const gap=37,end=x+bays*gap;
|
|
167
|
+
for(let i=0;i<=bays;i++){
|
|
168
|
+
for(const dy of [0,24]){
|
|
169
|
+
box(x+i*gap-2,y+dy-2,4,4.5,4.5,1.35,"steel","joint");
|
|
170
|
+
box(x+i*gap,y+dy,5,2.4,2.4,49,"steel","joint");
|
|
171
|
+
for(let z=12;z<51;z+=5)line([x+i*gap+.65,y+dy+2.5,z],[x+i*gap+1.7,y+dy+2.5,z],"edge",.37,.22);
|
|
172
|
+
}
|
|
173
|
+
const xx=x+i*gap+1.15;
|
|
174
|
+
for(const [low,high] of [[7,28],[29,51]])
|
|
175
|
+
line([xx,y+1.3,low],[xx,y+25.3,high],"belt",.96);
|
|
176
|
+
}
|
|
177
|
+
for(const z of [8,30,52]){
|
|
178
|
+
for(const dy of [.8,24.2])box(x+2.1,y+dy,z,end-x,1.8,2.2,"steel","joint");
|
|
179
|
+
if(z<52){
|
|
180
|
+
for(let i=0;i<bays;i++)box(x+i*gap+2.1,y+2,z+.3,gap-1,22,1.7,"deck","belt");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
for(let i=0;i<bays;i++){
|
|
184
|
+
const ax=x+i*gap+5;
|
|
185
|
+
if(i%3!==1)shippingBox(ax,y+4,10,16,16,12+i%2*3,"cartons");
|
|
186
|
+
if(i%4!==2)shippingBox(ax+17,y+6,10,12,14,9,"crate");
|
|
187
|
+
if(i%3===0)tote(ax+5,y+6,32,22,15,9);
|
|
188
|
+
else if(i%3===1)shippingBox(ax+4,y+6,32,22,15,13,"cartons");
|
|
189
|
+
else {
|
|
190
|
+
shippingBox(ax,y+4,32,13,14,10,"cartons");
|
|
191
|
+
shippingBox(ax+16,y+6,32,13,14,12,"cartons");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function fixedScene(){
|
|
196
|
+
rack(22,8,3);
|
|
197
|
+
rack(185,8,3);
|
|
198
|
+
for(const x of [15,308]){
|
|
199
|
+
box(x,8,4,3,33,5,"joint","belt");
|
|
200
|
+
box(x-.8,37,4,4.7,4.7,10,"steel","joint");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function pallet(point,z,kind,heading) {
|
|
204
|
+
const tr=placement(point,heading);
|
|
205
|
+
const w=31,h=31,px=-w/2,py=-h/2;
|
|
206
|
+
const feet=9.2;
|
|
207
|
+
for(const xx of [1,w-5.6])for(const yy of [1,h-4.65])
|
|
208
|
+
box(px+xx,py+yy,z-feet,4.55,3.6,feet,"wood","belt",tr);
|
|
209
|
+
for(const yy of [0,7.45,14.9,22.35,29.8]){
|
|
210
|
+
box(px,py+yy,z,w,Math.min(4.1,31-yy),2.45,"wood","belt",tr);
|
|
211
|
+
}
|
|
212
|
+
const base=z+2.46;
|
|
213
|
+
if(kind==="cartons"){
|
|
214
|
+
shippingBox(-12.9,-12,base,14,21.8,13,"cartons",tr);
|
|
215
|
+
shippingBox(1.45,-11,base,11.4,21.9,10.1,"cartons",tr);
|
|
216
|
+
shippingBox(-12,-10.6,base+13,11.2,19.4,9.6,"cartons",tr);
|
|
217
|
+
}else if(kind==="totes"){
|
|
218
|
+
tote(-12,-10.6,base,24,21.2,7.4,tr);
|
|
219
|
+
tote(-12,-10.6,base+7.7,24,21.2,7.4,tr);
|
|
220
|
+
}else {
|
|
221
|
+
shippingBox(-13.1,-12.1,base,26.2,24.2,16,"crate",tr);
|
|
222
|
+
const cap=base+16.11;
|
|
223
|
+
for(const xx of [-9,8])
|
|
224
|
+
flat(xx,-11.3,cap,2.6,22.6,"belt",tr);
|
|
225
|
+
for(const xx of [-7.7,9.3])for(const yy of [-8,8])bolt(xx,yy,cap+.08,.76,tr);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const footprint=[[-15,-6.8],[-12.3,-9],[12.3,-9],[15,-6.8],[15,6.8],[12.3,9],[-12.3,9],[-15,6.8]];
|
|
229
|
+
function cart(job,state) {
|
|
230
|
+
const z=state.deck,tr=placement(state.point,state.heading);
|
|
231
|
+
const forward=[Math.cos(state.heading),Math.sin(state.heading),0], across=[-forward[1],forward[0],0];
|
|
232
|
+
polygon(ring(tr([1,1.5,4.11]),X,Y,12,20),"shadow",null,.3,-.08);
|
|
233
|
+
for(const dx of [-8.8,8.8])for(const side of [-1,1]){
|
|
234
|
+
const center=tr([dx,side*9.2,7.2]);
|
|
235
|
+
const a=plus(center,scale(across,-1.35)),b=plus(center,scale(across,1.35));
|
|
236
|
+
cylinder(a,b,forward,Z,3.18,"heel",14);
|
|
237
|
+
if(dot(across,camera)*side>0){
|
|
238
|
+
const hub=plus(side===1?b:a,scale(across,side*.07));
|
|
239
|
+
disk(hub,forward,Z,2.2,"steel");
|
|
240
|
+
disk(plus(hub,scale(across,side*.04)),forward,Z,.92,"joint","edge",.36);
|
|
241
|
+
const theta=-(state.travel-side*9.2*state.rotation)/3.18;
|
|
242
|
+
for(let i=0;i<4;i++){
|
|
243
|
+
const a=theta+i*tau/4,c=Math.cos(a),s=Math.sin(a);
|
|
244
|
+
const v=plus(scale(forward,c),scale(Z,s));
|
|
245
|
+
line(plus(hub,scale(v,1.03)),plus(hub,scale(v,1.99)),"edge",.42,.5);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
slab(footprint,5.6,9.45,"steel","heel",tr);
|
|
250
|
+
slab(footprint.map(([a,b])=>[a*.975,b*.98]),9.45,10.3,"deck","steel",tr);
|
|
251
|
+
for (const direction of [-1,1]) {
|
|
252
|
+
const a=direction*15;
|
|
253
|
+
line(tr([a,-4.4,8.65]),tr([a,4.4,8.65]),"fine",.6);
|
|
254
|
+
for(const yy of [-4.65,4.65])
|
|
255
|
+
line(tr([direction*14.53,yy-.8,9.36]),tr([direction*14.53,yy+.8,9.36]),job.color,1.3,.35);
|
|
256
|
+
}
|
|
257
|
+
for(const side of [-1,1]){
|
|
258
|
+
const yy=side*5.9;
|
|
259
|
+
line(tr([-5.8,yy,10.5]),tr([5.8,yy,z-.47]),"edge",1.1,.32);
|
|
260
|
+
line(tr([5.8,yy,10.5]),tr([-5.8,yy,z-.47]),"belt",.9,.32);
|
|
261
|
+
}
|
|
262
|
+
box(-9,-6.6,z-.82,18,13.2,.82,"steel","heel",tr);
|
|
263
|
+
for(const a of [-5.8,5.8])line(tr([a,-5.1,z+.05]),tr([a,5.1,z+.05]),"edge",.46);
|
|
264
|
+
for(const a of [-12.4,12.4]){
|
|
265
|
+
disk(tr([a,-3.8,10.55]),X,Y,1.72,"heel","edge",.26);
|
|
266
|
+
disk(tr([a,-3.8,11.05]),X,Y,.91,state.waiting?"amber":state.moving?job.color:"joint",null,.3);
|
|
267
|
+
}
|
|
268
|
+
for(const a of [-10.6,10.6])for(const b of [-6.6,6.6])bolt(a,b,10.43,.64,tr);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function trajectory(a,b,time,start,end){
|
|
272
|
+
const u=limit((time-start)/(end-start),0,1);
|
|
273
|
+
const q=.23, peak=1/(1-q);
|
|
274
|
+
const s=u<q?peak*u*u/(2*q):u>1-q?1-peak*(1-u)**2/(2*q):peak*(u-q/2);
|
|
275
|
+
return mix(a,b,s);
|
|
276
|
+
}
|
|
277
|
+
function poseAt(path,time){
|
|
278
|
+
const leg=path.legs.find(leg=>time<leg.end);
|
|
279
|
+
if(!leg)return path.final;
|
|
280
|
+
const {from,to,start,end}=leg;
|
|
281
|
+
const s=trajectory(0,1,time,start,end);
|
|
282
|
+
return {
|
|
283
|
+
point:[mix(from.point[0],to.point[0],s),mix(from.point[1],to.point[1],s)],
|
|
284
|
+
heading:mix(from.heading,to.heading,s),travel:mix(from.travel,to.travel,s),rotation:mix(from.rotation,to.rotation,s),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function stateAt(j,time){
|
|
288
|
+
const path=time<j.leave?j.pickup:time<j.entry?j.approach:time<j.exit?j.crossing:time<j.release?j.outbound:j.depart;
|
|
289
|
+
const pose=poseAt(path,time);
|
|
290
|
+
const deck=time<=j.arrive?trajectory(lo,hi,time,j.dock+.26,j.liftEnd):trajectory(hi,lo,time,j.arrive+.21,j.lowerEnd);
|
|
291
|
+
const carrying=time>=j.dock && time<j.lowerEnd;
|
|
292
|
+
const cargo=carrying?pose:time>=j.lowerEnd?j.outbound.final:j.pickup.final;
|
|
293
|
+
const cargoHeight=carrying?Math.max(palletBottom,deck):palletBottom;
|
|
294
|
+
const waiting=time>=j.waitSince&&time<j.entry;
|
|
295
|
+
const moving=(time>j.start&&time<j.dock)||(time>j.leave&&time<j.arrive&&!waiting)||(time>j.release&&time<j.done);
|
|
296
|
+
return {...pose,deck,cargo,cargoHeight,moving,waiting};
|
|
297
|
+
}
|
|
298
|
+
function paint(context,items,colors,sort=true){
|
|
299
|
+
context.lineJoin="round";context.lineCap="round";
|
|
300
|
+
if(sort)items.sort((a,b)=>a.depth-b.depth);
|
|
301
|
+
for(const item of items){
|
|
302
|
+
context.beginPath();context.moveTo(...project(item.p[0]));
|
|
303
|
+
for(let i=1;i<item.p.length;i++)context.lineTo(...project(item.p[i]));
|
|
304
|
+
if(item.fill){context.closePath();context.fillStyle=colors[item.fill];context.fill();}
|
|
305
|
+
if(item.edge){context.strokeStyle=colors[item.edge];context.lineWidth=item.width;context.stroke();}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function palette(ink,surface){
|
|
309
|
+
const pixel=document.createElement("canvas");pixel.width=pixel.height=1;
|
|
310
|
+
const sampler=pixel.getContext("2d",{willReadFrequently:true});
|
|
311
|
+
const rgb=value=>{
|
|
312
|
+
sampler.fillStyle=value;sampler.fillRect(0,0,1,1);
|
|
313
|
+
return Array.from(sampler.getImageData(0,0,1,1).data).slice(0,3);
|
|
314
|
+
};
|
|
315
|
+
const a=rgb(ink),p=rgb(surface);
|
|
316
|
+
const tone=s=>"rgb("+p.map((c,i)=>Math.round(mix(c,a[i],s))).join(",")+")";
|
|
317
|
+
return {ink,edge:tone(.82),fine:tone(.64),floor:tone(.09),joint:tone(.23),shadow:tone(.16),
|
|
318
|
+
deck:tone(.12),steel:tone(.19),heel:tone(.51),kraft:tone(.21),wood:tone(.30),tote:tone(.34),
|
|
319
|
+
tape:tone(.08),sage:ink,amber:tone(.75),"paper-label":surface,belt:tone(.4)};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
fixedScene();const fixtures=queue;queue=[];
|
|
323
|
+
globalThis.ccdxToolWarehouse = context => {
|
|
324
|
+
let key,colors,ground,zoom,left,top;
|
|
325
|
+
return (_style,{time,width,height,dpr,ink,surface}) => {
|
|
326
|
+
const size=Math.min((width-10)/402,(height-8)/320)*dpr;
|
|
327
|
+
if(!(size>0))return;
|
|
328
|
+
const next=[width,height,dpr,ink,surface].join("|");
|
|
329
|
+
if(next!==key){
|
|
330
|
+
colors=palette(ink,surface);zoom=size;
|
|
331
|
+
left=context.canvas.width/2-35*zoom;top=context.canvas.height/2-123*zoom;
|
|
332
|
+
ground=document.createElement("canvas");
|
|
333
|
+
ground.width=context.canvas.width;ground.height=context.canvas.height;
|
|
334
|
+
const base=ground.getContext("2d");
|
|
335
|
+
base.setTransform(zoom,0,0,zoom,left,top);platform();paint(base,queue,colors,false);
|
|
336
|
+
queue=[];key=next;
|
|
337
|
+
}
|
|
338
|
+
const elapsed=Math.max(0,time);
|
|
339
|
+
const cycle=Math.floor(elapsed/total),phase=elapsed-cycle*total;
|
|
340
|
+
// The next cycle returns the loads along the same collision-tested trajectories.
|
|
341
|
+
const moment=cycle%2?total-phase:phase;
|
|
342
|
+
context.setTransform(1,0,0,1,0,0);context.drawImage(ground,0,0);
|
|
343
|
+
context.setTransform(zoom,0,0,zoom,left,top);
|
|
344
|
+
for(const job of jobs){
|
|
345
|
+
const state=stateAt(job,moment);
|
|
346
|
+
if(state.waiting)stopLine(job,"amber",1.18);
|
|
347
|
+
cart(job,state);pallet(state.cargo.point,state.cargoHeight,job.kind,state.cargo.heading);
|
|
348
|
+
}
|
|
349
|
+
paint(context,fixtures.concat(queue),colors);queue=[];
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
})();
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const root = document.getElementById("tool-activity");if (!root) return;
|
|
3
3
|
const el = id => document.getElementById(id), canvas = el("tool-canvas"), ctx = canvas.getContext?.("2d");
|
|
4
|
-
const styles = new Set(["production", "clock", "assembly", "sorter", "gantry", "rotary", "off"]), storageKey = "ccdx.dashboard.toolMotionStyle";
|
|
4
|
+
const styles = new Set(["production", "clock", "assembly", "sorter", "gantry", "rotary", "arm", "warehouse", "off"]), storageKey = "ccdx.dashboard.toolMotionStyle";
|
|
5
5
|
const pending = state => ["preparing", "waiting"].includes(state);
|
|
6
6
|
const phrase = (key, values = {}) => globalThis.ccdxLanguage.format(key, values);
|
|
7
7
|
const text = (id, key, values) => globalThis.ccdxLanguage.set(el(id), key, values);
|
|
8
8
|
const state = { scene: "idle", style: "production" };
|
|
9
9
|
const dashboardScript = document.currentScript.src;
|
|
10
|
-
|
|
10
|
+
const renderers = new Map();
|
|
11
|
+
const rendererName = () => ["arm", "warehouse"].includes(state.style) ? state.style : "machines";
|
|
12
|
+
const rendererFactories = { arm: "ccdxToolArm", warehouse: "ccdxToolWarehouse", machines: "ccdxToolMachines" };
|
|
11
13
|
try { const saved = localStorage.getItem(storageKey);if (styles.has(saved)) state.style = saved; } catch {}
|
|
12
14
|
const motion = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)") || { matches: false, addEventListener() {} };
|
|
13
15
|
let records = [], fresh = false, supported = false, visible = true, raf = 0, last = 0, start = performance.now(), expiry = null;
|
|
@@ -23,6 +25,7 @@
|
|
|
23
25
|
refreshAnimation();
|
|
24
26
|
}
|
|
25
27
|
function draw(now = performance.now()) {
|
|
28
|
+
const drawMachine = renderers.get(rendererName());
|
|
26
29
|
if (!drawMachine || !box.width || !box.height) return;
|
|
27
30
|
const dpr = Math.min(devicePixelRatio || 1, 1.5), width = box.width, height = box.height;
|
|
28
31
|
const w = Math.round(width * dpr), h = Math.round(height * dpr);
|
|
@@ -40,20 +43,31 @@
|
|
|
40
43
|
}
|
|
41
44
|
function refreshAnimation() {
|
|
42
45
|
cancelAnimationFrame(raf);raf = 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
const ready = shown() && state.style !== "off" && renderers.get(rendererName());
|
|
47
|
+
const moving = Boolean(ready && !motion.matches && animating());
|
|
48
|
+
root.dataset.paused = String(!moving);
|
|
49
|
+
if (!ready) {
|
|
50
|
+
if (shown() && state.style !== "off" && ctx) {
|
|
51
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
52
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
draw();if (moving) raf = requestAnimationFrame(animate);
|
|
46
57
|
}
|
|
47
58
|
function loadMachine() {
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
const name = rendererName();
|
|
60
|
+
if (!ctx || state.style === "off" || renderers.has(name)) return;
|
|
61
|
+
renderers.set(name, null);
|
|
50
62
|
const asset = new URL(dashboardScript);
|
|
51
|
-
asset.pathname = "/tool-activity-
|
|
63
|
+
asset.pathname = "/tool-activity-" + name + ".js";
|
|
52
64
|
const script = document.createElement("script");
|
|
53
65
|
script.src = asset.href;
|
|
54
66
|
script.addEventListener("load", () => {
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
const create = globalThis[rendererFactories[name]];
|
|
68
|
+
if (typeof create !== "function") return;
|
|
69
|
+
renderers.set(name, create(ctx));
|
|
70
|
+
if (rendererName() === name) refreshAnimation();
|
|
57
71
|
}, { once: true });
|
|
58
72
|
document.head.append(script);
|
|
59
73
|
}
|
package/src/dashboard/ui.css
CHANGED
|
@@ -336,6 +336,7 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
336
336
|
[data-sidebar-collapsed] .sidebar-chevron { transform: scaleX(-1); transform-origin: 14.5px 12px; }
|
|
337
337
|
[data-sidebar-collapsed] .sidebar nav a { position: relative; justify-content: center; gap: 0; padding-inline: 0; min-height: 36px; border-inline-end: 2px solid transparent; }
|
|
338
338
|
[data-sidebar-collapsed] .sidebar nav a > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
339
|
+
.sidebar-tooltip { position: fixed; z-index: 8; pointer-events: none; max-width: calc(100vw - 12px); padding: 5px 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
|
|
339
340
|
@media (max-width: 640px) {
|
|
340
341
|
[data-sidebar-collapsed] .sidebar { padding-inline-end: 0; }
|
|
341
342
|
[data-sidebar-collapsed] .sidebar-header { justify-content: flex-start; }
|
package/src/dashboard/ui.js
CHANGED
|
@@ -61,6 +61,50 @@ document.querySelector(".sidebar-brand").addEventListener("click", animateLogo);
|
|
|
61
61
|
const sidebarPreference = "ccdx.dashboard.sidebar";
|
|
62
62
|
const sidebarToggle = element("sidebar-toggle");
|
|
63
63
|
const sidebarLinks = element("sidebar-navigation").querySelectorAll("a");
|
|
64
|
+
const sidebarTooltip = element("sidebar-tooltip");
|
|
65
|
+
let hoveredSidebarLink, focusedSidebarLink, lastSidebarLink;
|
|
66
|
+
function updateSidebarTooltip() {
|
|
67
|
+
const link = lastSidebarLink === hoveredSidebarLink || lastSidebarLink === focusedSidebarLink
|
|
68
|
+
? lastSidebarLink : hoveredSidebarLink || focusedSidebarLink;
|
|
69
|
+
if (!link || document.documentElement.dataset.sidebarCollapsed !== "true") {
|
|
70
|
+
sidebarTooltip.hidden = true;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const name = link.querySelector("span");
|
|
74
|
+
localize(sidebarTooltip, name.dataset.i18n || name.textContent);
|
|
75
|
+
sidebarTooltip.hidden = false;
|
|
76
|
+
const anchor = link.getBoundingClientRect(), tip = sidebarTooltip.getBoundingClientRect();
|
|
77
|
+
const viewport = document.documentElement.clientWidth;
|
|
78
|
+
const rail = viewport > 640;
|
|
79
|
+
const x = rail ? anchor.right + 8 : anchor.left + (anchor.width - tip.width) / 2;
|
|
80
|
+
const y = rail ? anchor.top + (anchor.height - tip.height) / 2 : anchor.bottom + 6;
|
|
81
|
+
sidebarTooltip.style.left = `${Math.max(6, Math.min(x, viewport - tip.width - 6))}px`;
|
|
82
|
+
sidebarTooltip.style.top = `${Math.max(6, Math.min(y, window.innerHeight - tip.height - 6))}px`;
|
|
83
|
+
}
|
|
84
|
+
for (const link of sidebarLinks) {
|
|
85
|
+
link.addEventListener("pointerenter", event => {
|
|
86
|
+
if (event.pointerType === "touch") return;
|
|
87
|
+
lastSidebarLink = hoveredSidebarLink = link;
|
|
88
|
+
updateSidebarTooltip();
|
|
89
|
+
});
|
|
90
|
+
link.addEventListener("pointerleave", () => {
|
|
91
|
+
if (hoveredSidebarLink === link) hoveredSidebarLink = null;
|
|
92
|
+
updateSidebarTooltip();
|
|
93
|
+
});
|
|
94
|
+
link.addEventListener("focus", () => { lastSidebarLink = focusedSidebarLink = link;updateSidebarTooltip(); });
|
|
95
|
+
link.addEventListener("blur", () => {
|
|
96
|
+
if (focusedSidebarLink === link) focusedSidebarLink = null;
|
|
97
|
+
updateSidebarTooltip();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
document.addEventListener("keydown", event => {
|
|
101
|
+
if (event.key !== "Escape" || sidebarTooltip.hidden) return;
|
|
102
|
+
hoveredSidebarLink = focusedSidebarLink = null;
|
|
103
|
+
updateSidebarTooltip();
|
|
104
|
+
});
|
|
105
|
+
for (const event of ["resize", "scroll"]) window.addEventListener(event, () => {
|
|
106
|
+
if (!sidebarTooltip.hidden) updateSidebarTooltip();
|
|
107
|
+
}, { passive: true });
|
|
64
108
|
function setSidebarCollapsed(collapsed) {
|
|
65
109
|
if (collapsed) document.documentElement.dataset.sidebarCollapsed = "true";
|
|
66
110
|
else delete document.documentElement.dataset.sidebarCollapsed;
|
|
@@ -68,10 +112,7 @@ function setSidebarCollapsed(collapsed) {
|
|
|
68
112
|
const label = collapsed ? "sidebar_expand" : "sidebar_collapse";
|
|
69
113
|
localize(sidebarToggle, label, {}, "aria-label");
|
|
70
114
|
localize(sidebarToggle, label, {}, "title");
|
|
71
|
-
|
|
72
|
-
const name = link.querySelector("span");
|
|
73
|
-
localize(link, collapsed ? name.dataset.i18n || name.textContent : "", {}, "title");
|
|
74
|
-
}
|
|
115
|
+
updateSidebarTooltip();
|
|
75
116
|
}
|
|
76
117
|
try { setSidebarCollapsed(localStorage.getItem(sidebarPreference) === "collapsed"); }
|
|
77
118
|
catch { setSidebarCollapsed(false); }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const DASHBOARD_ASSETS = new Map([
|
|
2
|
+
["/", ["./dashboard/index.html", "text/html; charset=utf-8"]],
|
|
3
|
+
["/ui.css", ["./dashboard/ui.css", "text/css; charset=utf-8"]],
|
|
4
|
+
["/language.js", ["./dashboard/language.js", "text/javascript; charset=utf-8"]],
|
|
5
|
+
["/theme.js", ["./dashboard/theme.js", "text/javascript; charset=utf-8"]],
|
|
6
|
+
["/refresh.js", ["./dashboard/refresh.js", "text/javascript; charset=utf-8"]],
|
|
7
|
+
["/live.js", ["./dashboard/live.js", "text/javascript; charset=utf-8"]],
|
|
8
|
+
["/icons.js", ["./dashboard/icons.js", "text/javascript; charset=utf-8"]],
|
|
9
|
+
["/disclosure.js", ["./dashboard/disclosure.js", "text/javascript; charset=utf-8"]],
|
|
10
|
+
["/time.js", ["./dashboard/time.js", "text/javascript; charset=utf-8"]],
|
|
11
|
+
["/view-boundary.js", ["./dashboard/view-boundary.js", "text/javascript; charset=utf-8"]],
|
|
12
|
+
["/status.js", ["./dashboard/status.js", "text/javascript; charset=utf-8"]],
|
|
13
|
+
["/activity.js", ["./dashboard/activity.js", "text/javascript; charset=utf-8"]],
|
|
14
|
+
["/flow.js", ["./dashboard/flow.js", "text/javascript; charset=utf-8"]],
|
|
15
|
+
["/tool-activity-machines.js", ["./dashboard/tool-activity-machines.js", "text/javascript; charset=utf-8"]],
|
|
16
|
+
["/tool-activity-arm.js", ["./dashboard/tool-activity-arm.js", "text/javascript; charset=utf-8"]],
|
|
17
|
+
["/tool-activity-warehouse.js", ["./dashboard/tool-activity-warehouse.js", "text/javascript; charset=utf-8"]],
|
|
18
|
+
["/tool-activity.js", ["./dashboard/tool-activity.js", "text/javascript; charset=utf-8"]],
|
|
19
|
+
["/usage.js", ["./dashboard/usage.js", "text/javascript; charset=utf-8"]],
|
|
20
|
+
["/context.js", ["./dashboard/context.js", "text/javascript; charset=utf-8"]],
|
|
21
|
+
["/updates.js", ["./dashboard/updates.js", "text/javascript; charset=utf-8"]],
|
|
22
|
+
["/animation.js", ["./dashboard/animation.js", "text/javascript; charset=utf-8"]],
|
|
23
|
+
["/ui.js", ["./dashboard/ui.js", "text/javascript; charset=utf-8"]],
|
|
24
|
+
["/preferences.js", ["./dashboard/preferences.js", "text/javascript; charset=utf-8"]],
|
|
25
|
+
["/bark.js", ["./dashboard/bark.js", "text/javascript; charset=utf-8"]],
|
|
26
|
+
["/features.js", ["./dashboard/features.js", "text/javascript; charset=utf-8"]],
|
|
27
|
+
["/applications.js", ["./dashboard/applications.js", "text/javascript; charset=utf-8"]],
|
|
28
|
+
["/console.js", ["./dashboard/console.js", "text/javascript; charset=utf-8"]],
|
|
29
|
+
["/tools.js", ["./dashboard/tools.js", "text/javascript; charset=utf-8"]],
|
|
30
|
+
["/connections-loader.js", ["./dashboard/connections-loader.js", "text/javascript; charset=utf-8"]],
|
|
31
|
+
["/connections.js", ["./dashboard/connections.js", "text/javascript; charset=utf-8"]],
|
|
32
|
+
["/privacy.js", ["./dashboard/privacy.js", "text/javascript; charset=utf-8"]],
|
|
33
|
+
["/gemini.js", ["./dashboard/gemini.js", "text/javascript; charset=utf-8"]],
|
|
34
|
+
]);
|
|
35
|
+
const STANDALONE = new Set(["/language.js", "/theme.js", "/connections.js",
|
|
36
|
+
"/tool-activity-machines.js", "/tool-activity-arm.js", "/tool-activity-warehouse.js"]);
|
|
37
|
+
export const DASHBOARD_BUNDLE_ASSETS = [...DASHBOARD_ASSETS].filter(([name, [, type]]) =>
|
|
38
|
+
type.startsWith("text/javascript") && !STANDALONE.has(name)).map(([name]) => name);
|
|
39
|
+
export const DASHBOARD_PATHS = new Set([...DASHBOARD_ASSETS.keys(), "/dashboard.js"]);
|
package/src/dashboard.mjs
CHANGED
|
@@ -2,53 +2,36 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { isLoopbackAddress, isLoopbackHostHeader } from "./security.mjs";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { ADAPTER_VERSION } from "./running-adapter.mjs";
|
|
5
|
+
import { DASHBOARD_ASSETS, DASHBOARD_BUNDLE_ASSETS } from "./dashboard-assets.mjs";
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
["/privacy.js", ["./dashboard/privacy.js", "text/javascript; charset=utf-8"]],
|
|
35
|
-
["/gemini.js", ["./dashboard/gemini.js", "text/javascript; charset=utf-8"]],
|
|
36
|
-
]);
|
|
37
|
-
let bundle;
|
|
38
|
-
function assets() {
|
|
39
|
-
bundle ||= Promise.all([...ASSETS].map(async ([name, [file, type]]) => {
|
|
40
|
-
let body = await readFile(new URL(file, import.meta.url));
|
|
41
|
-
if (name === "/") body = Buffer.from(body.toString().replace(/(src|href)="(\/[a-z-]+\.(?:js|css))"/g, `$1="$2?v=${ADAPTER_VERSION}"`));
|
|
42
|
-
return [name, { body, type, etag: `"${createHash("sha256").update(body).digest("hex")}"` }];
|
|
43
|
-
})).then(async entries => {
|
|
44
|
-
const installed = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
|
|
45
|
-
if (installed.version !== ADAPTER_VERSION) throw new Error("Dashboard files changed; restart CCDX before loading the new dashboard");
|
|
46
|
-
// The Requests view loads its drawing code separately. Shared view code remains bundled.
|
|
47
|
-
const scripts = entries.filter(([name, asset]) => asset.type.startsWith("text/javascript") && !["/language.js", "/theme.js", "/tool-activity-machines.js"].includes(name));
|
|
48
|
-
const body = Buffer.concat(scripts.flatMap(([name, asset]) => [Buffer.from("// " + name + "\n"), asset.body, Buffer.from("\n;\n")]));
|
|
49
|
-
return new Map([...entries, ["/dashboard.js", { body, type: "text/javascript; charset=utf-8", etag: `"${createHash("sha256").update(body).digest("hex")}"` }]]);
|
|
50
|
-
}).catch(error => { bundle = null;throw error; });
|
|
51
|
-
return bundle;
|
|
7
|
+
const loaded = new Map();
|
|
8
|
+
let versionCheck;
|
|
9
|
+
function checkVersion() {
|
|
10
|
+
versionCheck ||= readFile(new URL("../package.json", import.meta.url), "utf8").then(text => {
|
|
11
|
+
if (JSON.parse(text).version !== ADAPTER_VERSION) throw new Error("Dashboard files changed; restart CCDX before loading the new dashboard");
|
|
12
|
+
}).finally(() => { versionCheck = null; });
|
|
13
|
+
return versionCheck;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function asset(name) {
|
|
17
|
+
if (!loaded.has(name)) loaded.set(name, (async () => {
|
|
18
|
+
await checkVersion();
|
|
19
|
+
let body, type;
|
|
20
|
+
if (name === "/dashboard.js") {
|
|
21
|
+
const files = await Promise.all(DASHBOARD_BUNDLE_ASSETS.map(asset));
|
|
22
|
+
body = Buffer.concat(files.flatMap(({ body }, i) => [Buffer.from("// " + DASHBOARD_BUNDLE_ASSETS[i] + "\n"), body, Buffer.from("\n;\n")]));
|
|
23
|
+
type = "text/javascript; charset=utf-8";
|
|
24
|
+
} else {
|
|
25
|
+
const [file, contentType] = DASHBOARD_ASSETS.get(name);
|
|
26
|
+
body = await readFile(new URL(file, import.meta.url));
|
|
27
|
+
type = contentType;
|
|
28
|
+
if (name === "/") body = Buffer.from(body.toString().replace(/(src|href)="(\/[a-z-]+\.(?:js|css))"/g, `$1="$2?v=${ADAPTER_VERSION}"`));
|
|
29
|
+
}
|
|
30
|
+
// A cold asset may be requested after the on-disk package was replaced.
|
|
31
|
+
await checkVersion();
|
|
32
|
+
return { body, type, etag: `"${createHash("sha256").update(body).digest("hex")}"` };
|
|
33
|
+
})().catch(error => { loaded.delete(name); throw error; }));
|
|
34
|
+
return loaded.get(name);
|
|
52
35
|
}
|
|
53
36
|
|
|
54
37
|
export async function serveDashboard(req, res, pathname) {
|
|
@@ -64,7 +47,7 @@ export async function serveDashboard(req, res, pathname) {
|
|
|
64
47
|
if (version && version !== ADAPTER_VERSION) {
|
|
65
48
|
res.writeHead(409, { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" });res.end("Dashboard version changed. Reload this page.");return;
|
|
66
49
|
}
|
|
67
|
-
const { body, type: contentType, etag } =
|
|
50
|
+
const { body, type: contentType, etag } = await asset(pathname);
|
|
68
51
|
const unchanged = pathname !== "/" && String(req.headers?.["if-none-match"] || "").split(/\s*,\s*/).includes(etag);
|
|
69
52
|
res.writeHead(unchanged ? 304 : 200, {
|
|
70
53
|
"Content-Type": contentType,
|