Skip to content

Commit 957dad3

Browse files
committed
Merge remote-tracking branch 'origin/develop' into staging-new
Signed-off-by: Alexander Onnikov <[email protected]>
2 parents bb5a44f + 1e7b531 commit 957dad3

File tree

25 files changed

+562
-456
lines changed

25 files changed

+562
-456
lines changed

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@
617617
},
618618
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
619619
"sourceMaps": true,
620+
"nodeVersionHint": 22,
620621
"cwd": "${workspaceRoot}/services/github/pod-github",
621622
"protocol": "inspector",
622623
"outputCapture": "std"

dev/tool/src/db.ts

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,9 +1319,41 @@ async function migrateAccount (
13191319
accountDB: AccountDB,
13201320
dryRun = true
13211321
): Promise<AccountUuid | undefined> {
1322-
const primaryKey: SocialKey = {
1323-
type: SocialIdType.EMAIL,
1324-
value: account.email
1322+
let primaryKey: SocialKey
1323+
let secondaryKey: SocialKey | undefined
1324+
1325+
if (account.githubId != null) {
1326+
if (account.githubUser == null) {
1327+
console.log('No github user found for github id', account.githubId)
1328+
return
1329+
}
1330+
1331+
primaryKey = {
1332+
type: SocialIdType.GITHUB,
1333+
value: account.githubUser
1334+
}
1335+
secondaryKey = !account.email.startsWith('github:')
1336+
? {
1337+
type: SocialIdType.EMAIL,
1338+
value: account.email
1339+
}
1340+
: undefined
1341+
} else if (account.openId != null) {
1342+
primaryKey = {
1343+
type: SocialIdType.OIDC,
1344+
value: account.openId
1345+
}
1346+
secondaryKey = !account.email.startsWith('openid:')
1347+
? {
1348+
type: SocialIdType.EMAIL,
1349+
value: account.email
1350+
}
1351+
: undefined
1352+
} else {
1353+
primaryKey = {
1354+
type: SocialIdType.EMAIL,
1355+
value: account.email
1356+
}
13251357
}
13261358

13271359
let personUuid: PersonUuid
@@ -1389,6 +1421,21 @@ async function migrateAccount (
13891421
}
13901422
}
13911423

1424+
if (secondaryKey != null) {
1425+
const existingSecondary = await accountDB.socialId.findOne(secondaryKey)
1426+
if (existingSecondary == null) {
1427+
if (!dryRun) {
1428+
await accountDB.socialId.insertOne({
1429+
...secondaryKey,
1430+
personUuid,
1431+
...verified
1432+
})
1433+
} else {
1434+
console.log('Creating secondary social id', { personUuid, confirmed: account.confirmed, secondaryKey })
1435+
}
1436+
}
1437+
}
1438+
13921439
return personUuid as AccountUuid
13931440
}
13941441

models/ai-assistant/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function createModel (builder: Builder): void {
3333
icon: aiAssistant.component.IconHulyAssistant,
3434
allowMultiple: false,
3535
createComponent: aiAssistant.component.Connect,
36+
configureComponent: aiAssistant.component.Connect,
3637
onDisconnect: aiAssistant.handler.DisconnectHandler,
3738
onDisconnectAll: aiAssistant.handler.DisconnectAllHandler,
3839
reconnectComponent: aiAssistant.component.Connect,

plugins/chat-resources/src/components/ChatNavigation.svelte

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@
116116
{ type: communication.type.Direct, order: 2 }
117117
],
118118
fixedTypes: [chat.masterTag.Thread, communication.type.Direct],
119-
specialSorting: {
120-
[communication.type.Direct]: 'alphabetical'
121-
},
122119
allowCreate: true,
123120
defaultSorting: 'recent',
124121
lookback: '2w',

plugins/client-resources/src/connection.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class RequestPromise {
7272
reject!: (reason?: any) => void
7373
reconnect?: () => void
7474

75-
// Required to proeprly handle rate limits
75+
// Required to properly handle rate limits
7676
sendData: () => void = () => {}
7777

7878
constructor (
@@ -92,14 +92,19 @@ class RequestPromise {
9292

9393
const globalRPCHandler: RPCHandler = new RPCHandler()
9494

95+
interface OnConnectHandler {
96+
resolve: () => void
97+
reject: (err: Error) => void
98+
}
99+
95100
class Connection implements ClientConnection {
96101
private websocket: ClientSocket | null = null
97102
binaryMode = false
98103
compressionMode = false
99104
private readonly requests = new Map<ReqId, RequestPromise>()
100105
private lastId = 0
101106
private interval: number | undefined
102-
private dialTimer: any | undefined
107+
private dialTimer: number | undefined
103108

104109
private sockets = 0
105110
private openAction: any
@@ -166,12 +171,13 @@ class Connection implements ClientConnection {
166171
}
167172

168173
private schedulePing (socketId: number): void {
169-
clearInterval(this.interval)
170174
this.pingResponse = Date.now()
171175
const wsocket = this.websocket
172-
const interval = setInterval(() => {
176+
177+
clearInterval(this.interval)
178+
this.interval = setInterval(() => {
173179
if (wsocket !== this.websocket) {
174-
clearInterval(interval)
180+
clearInterval(this.interval)
175181
return
176182
}
177183
if (!this.upgrading && this.pingResponse !== 0 && Date.now() - this.pingResponse > hangTimeout) {
@@ -203,14 +209,19 @@ class Connection implements ClientConnection {
203209
clearInterval(this.interval)
204210
}
205211
}, pingTimeout)
206-
this.interval = interval
207212
}
208213

209214
async close (): Promise<void> {
210215
this.closed = true
211216
clearTimeout(this.openAction)
212217
clearTimeout(this.dialTimer)
213218
clearInterval(this.interval)
219+
for (const handler of this.onConnectHandlers) {
220+
handler.reject(new Error('Connection closed'))
221+
}
222+
for (const req of this.requests.values()) {
223+
req.reject(new Error('Connection closed'))
224+
}
214225
if (this.websocket !== null) {
215226
this.websocket.close(1000)
216227
this.websocket = null
@@ -222,7 +233,7 @@ class Connection implements ClientConnection {
222233
}
223234

224235
delay = 0
225-
onConnectHandlers: (() => void)[] = []
236+
onConnectHandlers: OnConnectHandler[] = []
226237

227238
private waitOpenConnection (ctx: MeasureContext): Promise<void> | undefined {
228239
if (this.isConnected()) {
@@ -233,9 +244,10 @@ class Connection implements ClientConnection {
233244
'wait-connection',
234245
{},
235246
(ctx) =>
236-
new Promise((resolve) => {
237-
this.onConnectHandlers.push(() => {
238-
resolve()
247+
new Promise((resolve, reject) => {
248+
this.onConnectHandlers.push({
249+
resolve,
250+
reject
239251
})
240252
// Websocket is null for first time
241253
this.scheduleOpen(ctx, false)
@@ -294,7 +306,7 @@ class Connection implements ClientConnection {
294306
if (resp.error !== undefined) {
295307
if (resp.error?.code === UNAUTHORIZED.code || resp.terminate === true) {
296308
if (
297-
resp.error.code !== platform.status.WorkspaceArchived ||
309+
resp.error.code !== platform.status.WorkspaceArchived &&
298310
resp.error.code !== platform.status.WorkspaceNotFound
299311
) {
300312
Analytics.handleError(new PlatformError(resp.error))
@@ -350,7 +362,7 @@ class Connection implements ClientConnection {
350362

351363
// We need to clear dial timer, since we recieve hello response.
352364
clearTimeout(this.dialTimer)
353-
this.dialTimer = null
365+
this.dialTimer = undefined
354366
this.lastHash = (resp as HelloResponse).lastHash
355367

356368
const serverVersion = helloResp.serverVersion
@@ -374,7 +386,7 @@ class Connection implements ClientConnection {
374386
// Notify all waiting connection listeners
375387
const handlers = this.onConnectHandlers.splice(0, this.onConnectHandlers.length)
376388
for (const h of handlers) {
377-
h()
389+
h.resolve()
378390
}
379391

380392
for (const [, v] of this.requests.entries()) {
@@ -540,12 +552,10 @@ class Connection implements ClientConnection {
540552
return
541553
}
542554
this.websocket = wsocket
543-
const opened = false
544-
545-
if (this.dialTimer != null) {
555+
if (this.dialTimer === undefined) {
546556
this.dialTimer = setTimeout(() => {
547-
this.dialTimer = null
548-
if (!opened && !this.closed) {
557+
this.dialTimer = undefined
558+
if (!this.closed) {
549559
void this.opt?.onDialTimeout?.()?.catch((err) => {
550560
this.ctx.error('failed to handle dial timeout', { err })
551561
})
@@ -652,16 +662,15 @@ class Connection implements ClientConnection {
652662
ctx.withSync('send-hello', {}, () => this.websocket?.send(this.rpcHandler.serialize(helloRequest, false)))
653663
}
654664

655-
wsocket.onerror = (event: any) => {
665+
// FIX: remove undefined variable 'opened'
666+
wsocket.onerror = () => {
656667
if (this.websocket !== wsocket) {
657668
return
658669
}
659670
if (this.delay < 3) {
660671
this.delay += 1
661672
}
662-
if (opened) {
663-
console.error('client websocket error:', socketId, this.url, this.workspace, this.user)
664-
}
673+
console.error('client websocket error:', socketId, this.url, this.workspace, this.user)
665674
}
666675
}
667676

@@ -761,7 +770,7 @@ class Connection implements ClientConnection {
761770

762771
getAccount (): Promise<Account> {
763772
if (this.account !== undefined) {
764-
return clone(this.account)
773+
return Promise.resolve(clone(this.account))
765774
}
766775
return this.sendRequest({ method: 'getAccount', params: [] })
767776
}

0 commit comments

Comments
 (0)