@dao42/d42paas-front 0.9.7 → 0.9.8

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.
@@ -9114,18 +9114,19 @@ const mapValuesKey = (key, obj) => mapValues_1(obj, (value2) => value2[key]);
9114
9114
  const defaultDaoStoreData = {
9115
9115
  amDoing: "coding",
9116
9116
  _channel: null,
9117
- _channelConnected: false,
9117
+ _channelAvailable: false,
9118
9118
  appStatus: "drafted",
9119
+ currentAgentUserId: "",
9119
9120
  CRDTInfo: {
9120
9121
  agentUserId: ""
9121
9122
  },
9122
9123
  playgroundInfo: {
9123
- agentUserId: "",
9124
9124
  playgroundId: "",
9125
9125
  status: "EMPTY",
9126
9126
  dockerInfo: {},
9127
9127
  agentUsers: new Array(),
9128
9128
  playgroundIDEServerStatus: "NOT_SYNC",
9129
+ playgroundIDEServerStatusReason: "",
9129
9130
  filePath: "",
9130
9131
  fileTree: null,
9131
9132
  fileTreeIgnore: "",
@@ -9147,24 +9148,20 @@ const defaultDaoStoreData = {
9147
9148
  };
9148
9149
  const DaoStore = createStore$1("dao")(defaultDaoStoreData).extendSelectors((state, get2, _api) => ({
9149
9150
  channel: () => {
9150
- if (!get2._channelConnected()) {
9151
+ if (!get2._channelAvailable()) {
9151
9152
  return null;
9152
9153
  }
9153
9154
  return get2._channel();
9154
9155
  },
9155
9156
  currentAgentUser: () => {
9156
- const currentAgentUserId = get2.playgroundInfo().agentUserId;
9157
- if (!currentAgentUserId) {
9157
+ const currentAgentUserId2 = get2.currentAgentUserId();
9158
+ if (!currentAgentUserId2) {
9158
9159
  return null;
9159
9160
  }
9160
- return get2.playgroundInfo().agentUsers.find((item) => item.agentUserId === currentAgentUserId);
9161
+ return get2.playgroundInfo().agentUsers.find((item) => item.agentUserId === currentAgentUserId2);
9161
9162
  },
9162
9163
  getAgentUserById: (agentUserId) => {
9163
9164
  return get2.playgroundInfo().agentUsers.find((item) => item.agentUserId === agentUserId);
9164
- },
9165
- getTenantPlaygroundInfo: () => {
9166
- const playgroundInfo = get2.playgroundInfo();
9167
- return __spreadValues({}, playgroundInfo);
9168
9165
  }
9169
9166
  })).extendSelectors((state, get2, _api) => ({
9170
9167
  getFollowingAgentUser: () => {
@@ -9192,20 +9189,11 @@ const DaoStore = createStore$1("dao")(defaultDaoStoreData).extendSelectors((stat
9192
9189
  setChannel: (channel) => {
9193
9190
  set._channel(channel);
9194
9191
  },
9195
- setChannelConnected: (connected) => {
9196
- set._channelConnected(connected);
9197
- },
9198
9192
  setCRDTInfo: (crdt) => {
9199
9193
  set.CRDTInfo(crdt);
9200
9194
  },
9201
9195
  setPlaygroundInfo: (playgroundInfo) => {
9202
- const agentUserId = playgroundInfo.agentUserId || sessionStorage.getItem("agentUserId") || "";
9203
- if (playgroundInfo.agentUserId && agentUserId && playgroundInfo.agentUserId !== agentUserId) {
9204
- throw new Error("setPlaygroundInfo with wrong agentUserId");
9205
- }
9206
- set.playgroundInfo(__spreadProps(__spreadValues({}, playgroundInfo), {
9207
- agentUserId
9208
- }));
9196
+ set.playgroundInfo(playgroundInfo);
9209
9197
  }
9210
9198
  })).extendActions((set, get2, _api) => ({
9211
9199
  updateAgentUser: (agentUserId, data) => {
@@ -11439,7 +11427,7 @@ const Loading$1 = () => {
11439
11427
  });
11440
11428
  };
11441
11429
  const name$1 = "@dao42/d42paas-front";
11442
- const version = "0.9.6";
11430
+ const version = "0.9.7";
11443
11431
  const description = "d42paas front";
11444
11432
  const author = "dao42 paas team";
11445
11433
  const homepage = "https://github.com/dao42/d42paas_frontend#readme";
@@ -11640,7 +11628,7 @@ const requestChannelPathFromTicket = async (paasDomainPath, ticket, sdkVersion)
11640
11628
  return channelPath;
11641
11629
  };
11642
11630
  var index$8 = "";
11643
- const IsMe = (agentUserId) => sessionStorage.getItem("agentUserId") === agentUserId;
11631
+ const IsMe = (agentUserId) => store.dao.currentAgentUserId() === agentUserId;
11644
11632
  const getFileTreeItemByFilePath = (path) => {
11645
11633
  const filetree = store.dao.playgroundInfo().fileTree;
11646
11634
  let tree2 = null;
@@ -13808,6 +13796,108 @@ const ConnectionBroken = "connectionBroken";
13808
13796
  const AuthorizationFailed = "authorizationFailed";
13809
13797
  const ErrorFromServer = "errorFromServer";
13810
13798
  const Authorize = "auth";
13799
+ class TabsBroadcaster {
13800
+ constructor(name2, timeout2 = 2e3) {
13801
+ __publicField(this, "name");
13802
+ __publicField(this, "channel");
13803
+ __publicField(this, "_timeout");
13804
+ __publicField(this, "_messageId");
13805
+ __publicField(this, "_messages");
13806
+ __publicField(this, "_filter");
13807
+ this.name = name2;
13808
+ this._messageId = 0;
13809
+ this.channel = new BroadcastChannel(name2);
13810
+ this.channel.onmessage = (event) => this.receive(event);
13811
+ this._messages = [];
13812
+ this._timeout = timeout2;
13813
+ }
13814
+ setFilter(filter) {
13815
+ this._filter = filter;
13816
+ }
13817
+ send(content, timeout2) {
13818
+ const task = new TaskItem(timeout2 || this._timeout);
13819
+ const promise = new Promise((resolve2, reject) => {
13820
+ task._reject = reject;
13821
+ task._resolve = resolve2;
13822
+ });
13823
+ this._messages.push(task);
13824
+ this.channel.postMessage({
13825
+ id: this._messageId++,
13826
+ type: "request",
13827
+ payload: content
13828
+ });
13829
+ return promise;
13830
+ }
13831
+ answer(messageId, content) {
13832
+ this.channel.postMessage({
13833
+ id: messageId,
13834
+ type: "response",
13835
+ payload: content
13836
+ });
13837
+ }
13838
+ receive(event) {
13839
+ const data = event.data;
13840
+ if (data.type === "request") {
13841
+ if (!this._filter || this._filter(data.payload)) {
13842
+ this.answer(data.id, { active: true });
13843
+ }
13844
+ } else if (data.type === "response") {
13845
+ const task = this._messages[data.id];
13846
+ task.reject(data.payload);
13847
+ }
13848
+ }
13849
+ }
13850
+ class TaskItem {
13851
+ constructor(timeout2) {
13852
+ __publicField(this, "_resolve");
13853
+ __publicField(this, "_reject");
13854
+ __publicField(this, "_interval");
13855
+ this._interval = setTimeout(() => this.resolve({ active: false, reason: "timeout, no one uses it" }), timeout2);
13856
+ }
13857
+ resolve(value2) {
13858
+ clearTimeout(this._interval);
13859
+ this._resolve(value2);
13860
+ }
13861
+ reject(reason) {
13862
+ this._reject(reason);
13863
+ }
13864
+ }
13865
+ const broadcaster = new TabsBroadcaster("dao-paas", 500);
13866
+ let currentAgentUserId;
13867
+ async function findAvailableAgentUserId() {
13868
+ let currentAgentUserId2 = "";
13869
+ broadcaster.setFilter((item) => {
13870
+ return item.id === currentAgentUserId2;
13871
+ });
13872
+ const agentUsers = JSON.parse(localStorage.getItem("agentUsers") || "[]") || [];
13873
+ const requests = [];
13874
+ for (const item of agentUsers) {
13875
+ const response = broadcaster.send(item).then(() => {
13876
+ if (currentAgentUserId2 === "") {
13877
+ item.time = new Date().getTime();
13878
+ currentAgentUserId2 = item.id;
13879
+ localStorage.setItem("agentUsers", JSON.stringify(agentUsers));
13880
+ return Promise.resolve(currentAgentUserId2);
13881
+ }
13882
+ });
13883
+ requests.push(response);
13884
+ }
13885
+ return Promise.any(requests);
13886
+ }
13887
+ function storeAgentUserId(agentUserId) {
13888
+ const agentUsers = JSON.parse(localStorage.getItem("agentUsers") || "[]") || [];
13889
+ const item = agentUsers.find((value2) => value2.id == agentUserId);
13890
+ if (item) {
13891
+ item.time = new Date().getTime();
13892
+ } else {
13893
+ agentUsers.push({ id: agentUserId, time: new Date().getTime() });
13894
+ }
13895
+ localStorage.setItem("agentUsers", JSON.stringify(agentUsers));
13896
+ currentAgentUserId = agentUserId;
13897
+ }
13898
+ function verifyAgentUserId(agentUserId) {
13899
+ return agentUserId === currentAgentUserId;
13900
+ }
13811
13901
  class DaoChannel {
13812
13902
  constructor(ioPath, authOptions, maxReconnectionAttemps = 10) {
13813
13903
  __publicField(this, "socket");
@@ -13845,14 +13935,13 @@ class DaoChannel {
13845
13935
  });
13846
13936
  this.registerEventsOnSocket();
13847
13937
  this.socket.on("connect", () => {
13848
- actions.dao._channelConnected(true);
13849
13938
  this.authorize();
13850
13939
  if (store.dao.isReadyOffline()) {
13851
13940
  this.transitionOnline();
13852
13941
  }
13853
13942
  });
13854
13943
  this.socket.on("disconnect", () => {
13855
- actions.dao._channelConnected(false);
13944
+ actions.dao._channelAvailable(false);
13856
13945
  this.clearHeartbeatInterval();
13857
13946
  if (store.dao.isReady()) {
13858
13947
  this.transitionOffline();
@@ -13869,14 +13958,14 @@ class DaoChannel {
13869
13958
  return;
13870
13959
  }
13871
13960
  const { agentUserId } = data;
13872
- const sessionAgentUserId = sessionStorage.getItem("agentUserId");
13873
- if (sessionAgentUserId && sessionAgentUserId !== agentUserId) {
13874
- throw new Error(`Local sessionAgentUserId ${sessionAgentUserId} is not same with ${agentUserId}`);
13961
+ storeAgentUserId(agentUserId);
13962
+ if (!verifyAgentUserId(agentUserId)) {
13963
+ throw new Error(`The agentUserId ${agentUserId} is inconsistent`);
13875
13964
  }
13876
13965
  this.setHeartbeatInterval();
13877
- sessionStorage.setItem("agentUserId", agentUserId || "");
13878
13966
  this.authOptions.agentUserId = agentUserId;
13879
- this.updatePlaygroundInfoPartial({ agentUserId });
13967
+ this.updateCurrentAgentUserId(agentUserId);
13968
+ actions.dao._channelAvailable(true);
13880
13969
  });
13881
13970
  }
13882
13971
  authorize() {
@@ -13887,6 +13976,10 @@ class DaoChannel {
13887
13976
  throw new Error("The connection has not been established yet.");
13888
13977
  }
13889
13978
  this.socket.on("syncPlaygroundInfo", (playgroundInfo) => {
13979
+ if (playgroundInfo.playgroundIDEServerStatus === "ERROR") {
13980
+ this.transitionError(ErrorFromServer, playgroundInfo.playgroundIDEServerStatusReason);
13981
+ return;
13982
+ }
13890
13983
  if (store.dao.appStatus() === "loading") {
13891
13984
  this.initAppStatusLoadingPlaygroundInfo(playgroundInfo);
13892
13985
  return;
@@ -13897,6 +13990,20 @@ class DaoChannel {
13897
13990
  }
13898
13991
  console.warn("syncPlaygroundInfo event happened at a wrong appStatus");
13899
13992
  });
13993
+ this.socket.on("active", (message) => {
13994
+ const { success, reason } = message;
13995
+ const errorInfoMap = {
13996
+ SUCCESS: "\u6210\u529F",
13997
+ PLAYGROUND_NOT_EXISTED: "playground\u4E0D\u5B58\u5728",
13998
+ DOCKER_NOT_BIND: "playground\u672A\u7ED1\u5B9A\u5BB9\u5668",
13999
+ DOCKER_START_FAIL: "\u5BB9\u5668\u542F\u52A8\u5931\u8D25",
14000
+ RESOURCE_NOT_ENOUG: "\u670D\u52A1\u5668\u8D44\u6E90\u4E0D\u8DB3",
14001
+ BUSY: "\u670D\u52A1\u5668\u7E41\u5FD9"
14002
+ };
14003
+ if (!success) {
14004
+ this.transitionError(ErrorFromServer, `\u542F\u52A8\u5931\u8D25: ${errorInfoMap[reason] || reason}`);
14005
+ }
14006
+ });
13900
14007
  this.socket.on("following", (user) => {
13901
14008
  const { agentUsers } = store.dao.playgroundInfo();
13902
14009
  const index2 = agentUsers.findIndex((agentUser) => agentUser.userId === user.agentUserId);
@@ -13954,7 +14061,7 @@ class DaoChannel {
13954
14061
  this.updateCRDTInfo(data);
13955
14062
  });
13956
14063
  this.socket.on("fileContent", (data) => {
13957
- const { agentUsers, agentUserId } = store.dao.playgroundInfo();
14064
+ const agentUserId = store.dao.currentAgentUserId();
13958
14065
  const switchDoc = actions.currentDoc.switchDoc;
13959
14066
  const currentAgentUser = store.dao.currentAgentUser();
13960
14067
  const updateAgentUser = actions.dao.updateAgentUser;
@@ -14024,8 +14131,8 @@ class DaoChannel {
14024
14131
  this.socket.onAny((eventName, _data2) => {
14025
14132
  console.debug(`<< ${eventName}`);
14026
14133
  });
14027
- this.socket.on("errorHandler", (message) => {
14028
- this.transitionError(ErrorFromServer, message.content);
14134
+ this.socket.on("errorHandler", (data) => {
14135
+ this.transitionError(ErrorFromServer, `${data.name}: ${data.message}`);
14029
14136
  });
14030
14137
  }
14031
14138
  initAppStatusLoadingPlaygroundInfo(playgroundInfo) {
@@ -14075,6 +14182,9 @@ class DaoChannel {
14075
14182
  updatePlaygroundInfoPartial(data) {
14076
14183
  actions.dao.setPlaygroundInfo(__spreadValues(__spreadValues({}, store.dao.playgroundInfo()), data));
14077
14184
  }
14185
+ updateCurrentAgentUserId(agentUserId) {
14186
+ actions.dao.currentAgentUserId(agentUserId);
14187
+ }
14078
14188
  updateCRDTInfo(data) {
14079
14189
  actions.dao.setCRDTInfo(data);
14080
14190
  }
@@ -14298,9 +14408,13 @@ class DaoPaaS {
14298
14408
  async init() {
14299
14409
  console.debug(`sdk: init with ${this.paasDomainPath} passDomain`);
14300
14410
  const channelPath = await requestChannelPathFromTicket(this.paasDomainPath, this.paasOptions.ticket, this.sdkVersion);
14301
- const sessionAgentId = sessionStorage.getItem("agentUserId") || "";
14411
+ let agentUserId;
14412
+ try {
14413
+ agentUserId = await findAvailableAgentUserId();
14414
+ } catch (e2) {
14415
+ }
14302
14416
  const channel = new DaoChannel(channelPath, __spreadProps(__spreadValues({}, this.paasOptions), {
14303
- agentUserId: sessionAgentId
14417
+ agentUserId
14304
14418
  }));
14305
14419
  this._onMessage && channel.setOnMessage(this._onMessage);
14306
14420
  this._onError && channel.setOnError(this._onError);
@@ -158462,7 +158576,7 @@ const Skeleton = ({
158462
158576
  };
158463
158577
  function useFileTree() {
158464
158578
  const playgroundInfo = useStore$1().dao.playgroundInfo();
158465
- const { agentUserId, agentUsers } = playgroundInfo;
158579
+ const { agentUsers } = playgroundInfo;
158466
158580
  const getAgentUserById = store.dao.getAgentUserById;
158467
158581
  const once3 = react.exports.useRef(false);
158468
158582
  const user = useStore$1().dao.currentAgentUser();
@@ -158476,7 +158590,7 @@ function useFileTree() {
158476
158590
  if (fileOpened) {
158477
158591
  const crdt = {
158478
158592
  timestamp: Date.now(),
158479
- agentUserId,
158593
+ agentUserId: store.dao.currentAgentUserId(),
158480
158594
  file: {
158481
158595
  action: "Get",
158482
158596
  path: fileOpened
@@ -158485,7 +158599,7 @@ function useFileTree() {
158485
158599
  (_a2 = store.dao.channel()) == null ? void 0 : _a2.send("fileContent", crdt);
158486
158600
  once3.current = true;
158487
158601
  }
158488
- }, [agentUserId, fileOpened]);
158602
+ }, [fileOpened]);
158489
158603
  const getAgentUsers = react.exports.useCallback((path) => {
158490
158604
  return agentUsers.filter((u2) => {
158491
158605
  if (u2.followingAgentUserId) {
@@ -179406,7 +179520,6 @@ const FileTree = ({
179406
179520
  const moduleLoading = useStore$1().loading.moduleLoading();
179407
179521
  const setModuleLoading = actions.loading.setModuleLoading;
179408
179522
  const {
179409
- agentUserId,
179410
179523
  fileTree,
179411
179524
  fileTreeIgnore = ""
179412
179525
  } = useStore$1().dao.playgroundInfo();
@@ -179502,7 +179615,7 @@ const FileTree = ({
179502
179615
  if (amDoing === "coding") {
179503
179616
  const crdt = {
179504
179617
  timestamp: Date.now(),
179505
- agentUserId,
179618
+ agentUserId: store.dao.currentAgentUserId(),
179506
179619
  file: {
179507
179620
  action: "Get",
179508
179621
  path: items[0]
@@ -183075,8 +183188,6 @@ function AwaitingWithBuffer(outstanding, buffer) {
183075
183188
  }
183076
183189
  IoClient.AwaitingWithBuffer = AwaitingWithBuffer;
183077
183190
  AwaitingWithBuffer.prototype.applyClient = function(client2, operation) {
183078
- console.log("operation", operation);
183079
- console.log("buffer", this.buffer);
183080
183191
  const newBuffer = this.buffer.compose(operation);
183081
183192
  return new AwaitingWithBuffer(this.outstanding, newBuffer);
183082
183193
  };
@@ -206926,19 +207037,6 @@ function useTerminal(terminal, terminalRef, onData) {
206926
207037
  }
206927
207038
  onData == null ? void 0 : onData(character2);
206928
207039
  });
206929
- term.attachCustomKeyEventHandler((e2) => {
206930
- var _a2, _b2;
206931
- const ctrlOrCmd = e2.metaKey || e2.ctrlKey;
206932
- if (e2.type === "keyup")
206933
- return false;
206934
- if (e2.key === "v" && ctrlOrCmd) {
206935
- if ((_a2 = e2.view) == null ? void 0 : _a2.navigator.clipboard) {
206936
- (_b2 = e2.view) == null ? void 0 : _b2.navigator.clipboard.readText().then((res) => onData == null ? void 0 : onData(res));
206937
- }
206938
- return false;
206939
- }
206940
- return true;
206941
- });
206942
207040
  term.onResize(({
206943
207041
  cols,
206944
207042
  rows
@@ -207010,7 +207108,6 @@ function Console(_c2, ref) {
207010
207108
  }
207011
207109
  }), [options]);
207012
207110
  const {
207013
- agentUserId,
207014
207111
  dockerInfo
207015
207112
  } = useStore$1().dao.playgroundInfo();
207016
207113
  const amDoing = useStore$1().dao.amDoing();
@@ -207041,7 +207138,11 @@ function Console(_c2, ref) {
207041
207138
  terminal.reset();
207042
207139
  });
207043
207140
  const consoleHistorySetter = (consoleHistory, terminal2) => {
207044
- terminal2.write(consoleHistory);
207141
+ terminalWrite(consoleHistory);
207142
+ };
207143
+ const terminalWrite = (value2) => {
207144
+ const trimValue = value2.replace(/\r\n/g, "\n").replace(/\r|\n/g, "\r\n");
207145
+ terminal.write(trimValue);
207045
207146
  };
207046
207147
  const onData = (char2) => {
207047
207148
  var _a2;
@@ -207050,7 +207151,7 @@ function Console(_c2, ref) {
207050
207151
  }
207051
207152
  const crdt = {
207052
207153
  timestamp: Date.now(),
207053
- agentUserId,
207154
+ agentUserId: store.dao.currentAgentUserId(),
207054
207155
  console: {
207055
207156
  action: "Edit",
207056
207157
  value: char2
@@ -207071,8 +207172,10 @@ function Console(_c2, ref) {
207071
207172
  terminal.reset();
207072
207173
  return;
207073
207174
  }
207074
- if (terminalValueContent) {
207075
- terminal.write((terminalValueContent == null ? void 0 : terminalValueContent.value) || "");
207175
+ if (terminalValueContent && terminalValueContent.value) {
207176
+ terminalWrite(terminalValueContent.value);
207177
+ } else {
207178
+ terminalWrite("");
207076
207179
  }
207077
207180
  }, [CRDTInfo, terminal]);
207078
207181
  react.exports.useEffect(() => {
@@ -207084,7 +207187,7 @@ function Console(_c2, ref) {
207084
207187
  }, [dockerInfo, hasInit, terminal]);
207085
207188
  react.exports.useEffect(() => {
207086
207189
  if (terminal) {
207087
- consoleHistorySetter(consoleValue, terminal);
207190
+ consoleHistorySetter(consoleValue);
207088
207191
  }
207089
207192
  }, [consoleValue, terminal]);
207090
207193
  return /* @__PURE__ */ jsx(FollowLayout, {
@@ -207308,7 +207411,6 @@ const TerminalComponent = (_g2, ref) => {
207308
207411
  const userLabel = document.createElement("div");
207309
207412
  userLabel.classList.add("xterm-helper-user-label");
207310
207413
  const {
207311
- agentUserId,
207312
207414
  dockerInfo
207313
207415
  } = useStore$1().dao.playgroundInfo();
207314
207416
  const amDoing = useStore$1().dao.amDoing();
@@ -207340,7 +207442,7 @@ const TerminalComponent = (_g2, ref) => {
207340
207442
  }
207341
207443
  const crdt = {
207342
207444
  timestamp: Date.now(),
207343
- agentUserId,
207445
+ agentUserId: store.dao.currentAgentUserId(),
207344
207446
  terminal: {
207345
207447
  action: "Edit",
207346
207448
  value: char2