@blunking/codexlink 0.1.19 → 0.1.20
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 +222 -220
- package/blun-codex.ps1 +140 -140
- package/package.json +37 -37
- package/start-codex-agent.ps1 +715 -715
- package/telegram-doctor.ps1 +205 -205
- package/telegram-plugin/lib/bridge.js +14 -1
- package/telegram-plugin/lib/storage.js +25 -25
- package/telegram-setup.ps1 +143 -143
- package/telegram-status.ps1 +256 -256
- package/telegram-title-embed.ps1 +98 -98
- package/telegram-title-watcher.ps1 +102 -102
package/telegram-status.ps1
CHANGED
|
@@ -1,169 +1,169 @@
|
|
|
1
1
|
param(
|
|
2
|
-
[string]$Profile = "default"
|
|
3
|
-
)
|
|
4
|
-
|
|
5
|
-
$ErrorActionPreference = "Stop"
|
|
6
|
-
|
|
7
|
-
function Try-ReadJson {
|
|
8
|
-
param([string]$Path)
|
|
9
|
-
if (-not (Test-Path $Path)) { return $null }
|
|
10
|
-
try { return Get-Content -Raw -Path $Path | ConvertFrom-Json } catch { return $null }
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function Read-DotEnvFile {
|
|
14
|
-
param([string]$Path)
|
|
15
|
-
$values = @{}
|
|
16
|
-
if (-not (Test-Path $Path)) { return $values }
|
|
17
|
-
foreach ($line in (Get-Content -Path $Path)) {
|
|
18
|
-
if (-not $line) { continue }
|
|
19
|
-
if ($line.Trim().StartsWith("#")) { continue }
|
|
20
|
-
$parts = $line -split "=", 2
|
|
21
|
-
if ($parts.Count -ne 2) { continue }
|
|
22
|
-
$values[$parts[0].Trim()] = $parts[1]
|
|
23
|
-
}
|
|
24
|
-
return $values
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function Test-PidAlive {
|
|
28
|
-
param([int]$ProcId)
|
|
29
|
-
if ($ProcId -le 0) { return $false }
|
|
30
|
-
return $null -ne (Get-Process -Id $ProcId -ErrorAction SilentlyContinue)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function Normalize-Preview {
|
|
2
|
+
[string]$Profile = "default"
|
|
3
|
+
)
|
|
4
|
+
|
|
5
|
+
$ErrorActionPreference = "Stop"
|
|
6
|
+
|
|
7
|
+
function Try-ReadJson {
|
|
8
|
+
param([string]$Path)
|
|
9
|
+
if (-not (Test-Path $Path)) { return $null }
|
|
10
|
+
try { return Get-Content -Raw -Path $Path | ConvertFrom-Json } catch { return $null }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function Read-DotEnvFile {
|
|
14
|
+
param([string]$Path)
|
|
15
|
+
$values = @{}
|
|
16
|
+
if (-not (Test-Path $Path)) { return $values }
|
|
17
|
+
foreach ($line in (Get-Content -Path $Path)) {
|
|
18
|
+
if (-not $line) { continue }
|
|
19
|
+
if ($line.Trim().StartsWith("#")) { continue }
|
|
20
|
+
$parts = $line -split "=", 2
|
|
21
|
+
if ($parts.Count -ne 2) { continue }
|
|
22
|
+
$values[$parts[0].Trim()] = $parts[1]
|
|
23
|
+
}
|
|
24
|
+
return $values
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function Test-PidAlive {
|
|
28
|
+
param([int]$ProcId)
|
|
29
|
+
if ($ProcId -le 0) { return $false }
|
|
30
|
+
return $null -ne (Get-Process -Id $ProcId -ErrorAction SilentlyContinue)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function Normalize-Preview {
|
|
34
34
|
param([string]$Value, [int]$MaxLength = 72)
|
|
35
35
|
$text = [string]$Value
|
|
36
36
|
$text = $text -replace "\s+", " "
|
|
37
37
|
$text = $text.Trim()
|
|
38
|
-
if (-not $text) { return "" }
|
|
39
|
-
if ($text.Length -le $MaxLength) { return $text }
|
|
40
|
-
return ($text.Substring(0, [Math]::Max(0, $MaxLength - 3)).TrimEnd() + "...")
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function Get-IsoAgeMs {
|
|
44
|
-
param([string]$IsoString)
|
|
45
|
-
if (-not $IsoString) { return [double]::PositiveInfinity }
|
|
46
|
-
try {
|
|
47
|
-
$parsed = [DateTimeOffset]::Parse($IsoString)
|
|
48
|
-
return [Math]::Max(0, ([DateTimeOffset]::UtcNow - $parsed.ToUniversalTime()).TotalMilliseconds)
|
|
49
|
-
} catch {
|
|
50
|
-
return [double]::PositiveInfinity
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function Resolve-ConfiguredPath {
|
|
55
|
-
param([string]$Value, [string]$RuntimeRoot)
|
|
56
|
-
if (-not $Value) { return "" }
|
|
57
|
-
$expanded = [Environment]::ExpandEnvironmentVariables($Value)
|
|
58
|
-
if ([System.IO.Path]::IsPathRooted($expanded)) { return $expanded }
|
|
59
|
-
return [System.IO.Path]::GetFullPath((Join-Path $RuntimeRoot $expanded))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function Get-TelegramPluginRoot {
|
|
63
|
-
param([string]$RuntimeRoot)
|
|
64
|
-
|
|
65
|
-
$candidates = @()
|
|
66
|
-
if ($env:BLUN_CODEX_TELEGRAM_PLUGIN_ROOT) {
|
|
67
|
-
$candidates += $env:BLUN_CODEX_TELEGRAM_PLUGIN_ROOT
|
|
68
|
-
}
|
|
69
|
-
$candidates += (Join-Path $RuntimeRoot "telegram-plugin")
|
|
70
|
-
|
|
71
|
-
foreach ($candidate in $candidates) {
|
|
72
|
-
if (-not $candidate) { continue }
|
|
73
|
-
if ((Test-Path (Join-Path $candidate "app-server-cli.js")) -and (Test-Path (Join-Path $candidate "sidecar-manager.js"))) {
|
|
74
|
-
return $candidate
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return $null
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function Get-ProfilePath {
|
|
82
|
-
param(
|
|
83
|
-
[string]$RuntimeRoot,
|
|
84
|
-
[string]$ProfileName
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
$normalized = [string]$ProfileName
|
|
88
|
-
if (-not $normalized) { $normalized = "" }
|
|
89
|
-
$normalized = $normalized.ToLower()
|
|
90
|
-
$candidates = @()
|
|
91
|
-
if ($env:BLUN_CODEX_PROFILE_ROOT) {
|
|
92
|
-
$candidates += (Join-Path $env:BLUN_CODEX_PROFILE_ROOT ($normalized + ".json"))
|
|
93
|
-
}
|
|
94
|
-
$candidates += (Join-Path $env:USERPROFILE (".codex\\profiles\\codexlink\\" + $normalized + ".json"))
|
|
95
|
-
$candidates += (Join-Path $RuntimeRoot ("profiles\\" + $normalized + ".json"))
|
|
96
|
-
|
|
97
|
-
foreach ($candidate in $candidates) {
|
|
98
|
-
if ($candidate -and (Test-Path $candidate)) {
|
|
99
|
-
return $candidate
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return $candidates[-1]
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
$runtimeRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
107
|
-
$profilePath = Get-ProfilePath -RuntimeRoot $runtimeRoot -ProfileName $Profile
|
|
108
|
-
$profileJson = Try-ReadJson -Path $profilePath
|
|
109
|
-
$profileAgent = if ($profileJson -and $profileJson.agent_name) { [string]$profileJson.agent_name } else { $Profile.ToLower() }
|
|
110
|
-
$runtimeDir = Join-Path $env:USERPROFILE (".codex\\runtimes\\" + $profileAgent)
|
|
111
|
-
$stateDir = if ($profileJson -and $profileJson.telegram -and $profileJson.telegram.state_dir) {
|
|
112
|
-
Resolve-ConfiguredPath -Value ([string]$profileJson.telegram.state_dir) -RuntimeRoot $runtimeRoot
|
|
113
|
-
} else {
|
|
114
|
-
Join-Path $env:USERPROFILE (".codex\\channels\\telegram-" + $profileAgent)
|
|
115
|
-
}
|
|
116
|
-
$currentRuntime = Try-ReadJson -Path (Join-Path $runtimeDir "current-remote-runtime.json")
|
|
117
|
-
$state = Try-ReadJson -Path (Join-Path $stateDir "state.json")
|
|
118
|
-
$envFile = Read-DotEnvFile -Path (Join-Path $stateDir ".env")
|
|
119
|
-
$loadedThreads = @()
|
|
120
|
-
$ambientQueueTtlMs = if ($envFile["BLUN_TELEGRAM_AMBIENT_QUEUE_TTL_MS"]) { [int]$envFile["BLUN_TELEGRAM_AMBIENT_QUEUE_TTL_MS"] } else { 600000 }
|
|
121
|
-
$queue = @($state.queue)
|
|
122
|
-
$staleAmbientQueued = @($queue | Where-Object {
|
|
123
|
-
$_.status -eq "queued" -and
|
|
124
|
-
[string]$_.relevance -eq "ambient" -and
|
|
125
|
-
(Get-IsoAgeMs -IsoString ([string]$_.ts)) -ge $ambientQueueTtlMs
|
|
126
|
-
})
|
|
127
|
-
$queued = @($queue | Where-Object {
|
|
128
|
-
if ($_.status -ne "queued") { return $false }
|
|
129
|
-
if ([string]$_.relevance -eq "ambient" -and (Get-IsoAgeMs -IsoString ([string]$_.ts)) -ge $ambientQueueTtlMs) { return $false }
|
|
130
|
-
return $true
|
|
131
|
-
})
|
|
132
|
-
$directQueued = @($queued | Where-Object { @("direct", "lane") -contains [string]$_.relevance })
|
|
133
|
-
$ambientQueued = @($queued | Where-Object { [string]$_.relevance -eq "ambient" })
|
|
134
|
-
$escalationQueued = @($queued | Where-Object { [string]$_.relevance -eq "escalation" })
|
|
135
|
-
$submitted = @($queue | Where-Object { $_.status -eq "submitted" })
|
|
136
|
-
$delivered = @($queue | Where-Object { $_.status -eq "delivered" })
|
|
137
|
-
$errors = @($queue | Where-Object { $_.status -eq "error" })
|
|
38
|
+
if (-not $text) { return "" }
|
|
39
|
+
if ($text.Length -le $MaxLength) { return $text }
|
|
40
|
+
return ($text.Substring(0, [Math]::Max(0, $MaxLength - 3)).TrimEnd() + "...")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function Get-IsoAgeMs {
|
|
44
|
+
param([string]$IsoString)
|
|
45
|
+
if (-not $IsoString) { return [double]::PositiveInfinity }
|
|
46
|
+
try {
|
|
47
|
+
$parsed = [DateTimeOffset]::Parse($IsoString)
|
|
48
|
+
return [Math]::Max(0, ([DateTimeOffset]::UtcNow - $parsed.ToUniversalTime()).TotalMilliseconds)
|
|
49
|
+
} catch {
|
|
50
|
+
return [double]::PositiveInfinity
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function Resolve-ConfiguredPath {
|
|
55
|
+
param([string]$Value, [string]$RuntimeRoot)
|
|
56
|
+
if (-not $Value) { return "" }
|
|
57
|
+
$expanded = [Environment]::ExpandEnvironmentVariables($Value)
|
|
58
|
+
if ([System.IO.Path]::IsPathRooted($expanded)) { return $expanded }
|
|
59
|
+
return [System.IO.Path]::GetFullPath((Join-Path $RuntimeRoot $expanded))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function Get-TelegramPluginRoot {
|
|
63
|
+
param([string]$RuntimeRoot)
|
|
64
|
+
|
|
65
|
+
$candidates = @()
|
|
66
|
+
if ($env:BLUN_CODEX_TELEGRAM_PLUGIN_ROOT) {
|
|
67
|
+
$candidates += $env:BLUN_CODEX_TELEGRAM_PLUGIN_ROOT
|
|
68
|
+
}
|
|
69
|
+
$candidates += (Join-Path $RuntimeRoot "telegram-plugin")
|
|
70
|
+
|
|
71
|
+
foreach ($candidate in $candidates) {
|
|
72
|
+
if (-not $candidate) { continue }
|
|
73
|
+
if ((Test-Path (Join-Path $candidate "app-server-cli.js")) -and (Test-Path (Join-Path $candidate "sidecar-manager.js"))) {
|
|
74
|
+
return $candidate
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return $null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function Get-ProfilePath {
|
|
82
|
+
param(
|
|
83
|
+
[string]$RuntimeRoot,
|
|
84
|
+
[string]$ProfileName
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
$normalized = [string]$ProfileName
|
|
88
|
+
if (-not $normalized) { $normalized = "" }
|
|
89
|
+
$normalized = $normalized.ToLower()
|
|
90
|
+
$candidates = @()
|
|
91
|
+
if ($env:BLUN_CODEX_PROFILE_ROOT) {
|
|
92
|
+
$candidates += (Join-Path $env:BLUN_CODEX_PROFILE_ROOT ($normalized + ".json"))
|
|
93
|
+
}
|
|
94
|
+
$candidates += (Join-Path $env:USERPROFILE (".codex\\profiles\\codexlink\\" + $normalized + ".json"))
|
|
95
|
+
$candidates += (Join-Path $RuntimeRoot ("profiles\\" + $normalized + ".json"))
|
|
96
|
+
|
|
97
|
+
foreach ($candidate in $candidates) {
|
|
98
|
+
if ($candidate -and (Test-Path $candidate)) {
|
|
99
|
+
return $candidate
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return $candidates[-1]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
$runtimeRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
107
|
+
$profilePath = Get-ProfilePath -RuntimeRoot $runtimeRoot -ProfileName $Profile
|
|
108
|
+
$profileJson = Try-ReadJson -Path $profilePath
|
|
109
|
+
$profileAgent = if ($profileJson -and $profileJson.agent_name) { [string]$profileJson.agent_name } else { $Profile.ToLower() }
|
|
110
|
+
$runtimeDir = Join-Path $env:USERPROFILE (".codex\\runtimes\\" + $profileAgent)
|
|
111
|
+
$stateDir = if ($profileJson -and $profileJson.telegram -and $profileJson.telegram.state_dir) {
|
|
112
|
+
Resolve-ConfiguredPath -Value ([string]$profileJson.telegram.state_dir) -RuntimeRoot $runtimeRoot
|
|
113
|
+
} else {
|
|
114
|
+
Join-Path $env:USERPROFILE (".codex\\channels\\telegram-" + $profileAgent)
|
|
115
|
+
}
|
|
116
|
+
$currentRuntime = Try-ReadJson -Path (Join-Path $runtimeDir "current-remote-runtime.json")
|
|
117
|
+
$state = Try-ReadJson -Path (Join-Path $stateDir "state.json")
|
|
118
|
+
$envFile = Read-DotEnvFile -Path (Join-Path $stateDir ".env")
|
|
119
|
+
$loadedThreads = @()
|
|
120
|
+
$ambientQueueTtlMs = if ($envFile["BLUN_TELEGRAM_AMBIENT_QUEUE_TTL_MS"]) { [int]$envFile["BLUN_TELEGRAM_AMBIENT_QUEUE_TTL_MS"] } else { 600000 }
|
|
121
|
+
$queue = @($state.queue)
|
|
122
|
+
$staleAmbientQueued = @($queue | Where-Object {
|
|
123
|
+
$_.status -eq "queued" -and
|
|
124
|
+
[string]$_.relevance -eq "ambient" -and
|
|
125
|
+
(Get-IsoAgeMs -IsoString ([string]$_.ts)) -ge $ambientQueueTtlMs
|
|
126
|
+
})
|
|
127
|
+
$queued = @($queue | Where-Object {
|
|
128
|
+
if ($_.status -ne "queued") { return $false }
|
|
129
|
+
if ([string]$_.relevance -eq "ambient" -and (Get-IsoAgeMs -IsoString ([string]$_.ts)) -ge $ambientQueueTtlMs) { return $false }
|
|
130
|
+
return $true
|
|
131
|
+
})
|
|
132
|
+
$directQueued = @($queued | Where-Object { @("direct", "lane") -contains [string]$_.relevance })
|
|
133
|
+
$ambientQueued = @($queued | Where-Object { [string]$_.relevance -eq "ambient" })
|
|
134
|
+
$escalationQueued = @($queued | Where-Object { [string]$_.relevance -eq "escalation" })
|
|
135
|
+
$submitted = @($queue | Where-Object { $_.status -eq "submitted" })
|
|
136
|
+
$delivered = @($queue | Where-Object { $_.status -eq "delivered" })
|
|
137
|
+
$errors = @($queue | Where-Object { $_.status -eq "error" })
|
|
138
138
|
$pendingReplies = @($state.pendingReplies | Where-Object { -not $_.sentAt -and @("error", "expired", "ignored_bot", "suppressed_ack", "superseded", "sent", "stale_thread") -notcontains $_.status })
|
|
139
139
|
$expiredPendingReplies = @($state.pendingReplies | Where-Object { $_.status -eq "expired" })
|
|
140
|
-
$pollerPid = if (Test-Path (Join-Path $stateDir "poller.pid")) { (Get-Content -Raw (Join-Path $stateDir "poller.pid")).Trim() } else { $null }
|
|
141
|
-
$dispatcherPid = if (Test-Path (Join-Path $stateDir "dispatcher.pid")) { (Get-Content -Raw (Join-Path $stateDir "dispatcher.pid")).Trim() } else { $null }
|
|
142
|
-
$responderPid = if (Test-Path (Join-Path $stateDir "responder.pid")) { (Get-Content -Raw (Join-Path $stateDir "responder.pid")).Trim() } else { $null }
|
|
143
|
-
$stateThreadId = if ($state.currentThreadId) { [string]$state.currentThreadId } else { "" }
|
|
144
|
-
$runtimeThreadId = if ($currentRuntime -and $currentRuntime.thread_id) { [string]$currentRuntime.thread_id } else { "" }
|
|
145
|
-
$telegramPluginRoot = Get-TelegramPluginRoot -RuntimeRoot $runtimeRoot
|
|
146
|
-
$dispatchMode = if ($envFile["BLUN_TELEGRAM_DISPATCH_MODE"]) { [string]$envFile["BLUN_TELEGRAM_DISPATCH_MODE"] } else { "deferred" }
|
|
147
|
-
$idleCooldownMs = if ($envFile["BLUN_TELEGRAM_IDLE_COOLDOWN_MS"]) { [int]$envFile["BLUN_TELEGRAM_IDLE_COOLDOWN_MS"] } else { 15000 }
|
|
148
|
-
$eligibleQueued = if ($dispatchMode -eq "legacy") {
|
|
149
|
-
@($queued)
|
|
150
|
-
} else {
|
|
151
|
-
@($queued | Where-Object {
|
|
152
|
-
[string]$_.chatType -eq "private" -or @("direct", "lane", "escalation") -contains [string]$_.relevance
|
|
153
|
-
})
|
|
154
|
-
}
|
|
140
|
+
$pollerPid = if (Test-Path (Join-Path $stateDir "poller.pid")) { (Get-Content -Raw (Join-Path $stateDir "poller.pid")).Trim() } else { $null }
|
|
141
|
+
$dispatcherPid = if (Test-Path (Join-Path $stateDir "dispatcher.pid")) { (Get-Content -Raw (Join-Path $stateDir "dispatcher.pid")).Trim() } else { $null }
|
|
142
|
+
$responderPid = if (Test-Path (Join-Path $stateDir "responder.pid")) { (Get-Content -Raw (Join-Path $stateDir "responder.pid")).Trim() } else { $null }
|
|
143
|
+
$stateThreadId = if ($state.currentThreadId) { [string]$state.currentThreadId } else { "" }
|
|
144
|
+
$runtimeThreadId = if ($currentRuntime -and $currentRuntime.thread_id) { [string]$currentRuntime.thread_id } else { "" }
|
|
145
|
+
$telegramPluginRoot = Get-TelegramPluginRoot -RuntimeRoot $runtimeRoot
|
|
146
|
+
$dispatchMode = if ($envFile["BLUN_TELEGRAM_DISPATCH_MODE"]) { [string]$envFile["BLUN_TELEGRAM_DISPATCH_MODE"] } else { "deferred" }
|
|
147
|
+
$idleCooldownMs = if ($envFile["BLUN_TELEGRAM_IDLE_COOLDOWN_MS"]) { [int]$envFile["BLUN_TELEGRAM_IDLE_COOLDOWN_MS"] } else { 15000 }
|
|
148
|
+
$eligibleQueued = if ($dispatchMode -eq "legacy") {
|
|
149
|
+
@($queued)
|
|
150
|
+
} else {
|
|
151
|
+
@($queued | Where-Object {
|
|
152
|
+
[string]$_.chatType -eq "private" -or @("direct", "lane", "escalation") -contains [string]$_.relevance
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
155
|
$nextQueued = @(
|
|
156
|
-
$eligibleQueued |
|
|
157
|
-
Sort-Object `
|
|
158
|
-
@{ Expression = {
|
|
159
|
-
if ([string]$_.relevance -eq "escalation") { 0 }
|
|
160
|
-
elseif ([string]$_.chatType -eq "private" -or @("direct", "lane") -contains [string]$_.relevance) { 1 }
|
|
161
|
-
else { 2 }
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
@{ Expression = { [string]$_.ts } },
|
|
165
|
-
@{ Expression = { [int]$_.messageId } } |
|
|
166
|
-
Select-Object -First 1
|
|
156
|
+
$eligibleQueued |
|
|
157
|
+
Sort-Object `
|
|
158
|
+
@{ Expression = {
|
|
159
|
+
if ([string]$_.relevance -eq "escalation") { 0 }
|
|
160
|
+
elseif ([string]$_.chatType -eq "private" -or @("direct", "lane") -contains [string]$_.relevance) { 1 }
|
|
161
|
+
else { 2 }
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
@{ Expression = { [string]$_.ts } },
|
|
165
|
+
@{ Expression = { [int]$_.messageId } } |
|
|
166
|
+
Select-Object -First 1
|
|
167
167
|
)
|
|
168
168
|
$nextPendingReply = @(
|
|
169
169
|
$pendingReplies |
|
|
@@ -179,91 +179,91 @@ $waitReason = if ($pendingReplies.Count -gt 0) {
|
|
|
179
179
|
} elseif ($state.lastInjectAt -and (Get-IsoAgeMs -IsoString ([string]$state.lastInjectAt)) -lt $idleCooldownMs) {
|
|
180
180
|
"wartet auf Ruhe"
|
|
181
181
|
} else {
|
|
182
|
-
"wartet in Queue"
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if ($currentRuntime) {
|
|
186
|
-
if ($stateThreadId) {
|
|
187
|
-
if ($currentRuntime.PSObject.Properties.Name.Contains("thread_id")) {
|
|
188
|
-
$currentRuntime.thread_id = $stateThreadId
|
|
189
|
-
} else {
|
|
190
|
-
$currentRuntime | Add-Member -NotePropertyName "thread_id" -NotePropertyValue $stateThreadId
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if ($pollerPid) {
|
|
194
|
-
if ($currentRuntime.PSObject.Properties.Name.Contains("poller_pid")) {
|
|
195
|
-
$currentRuntime.poller_pid = $pollerPid
|
|
196
|
-
} else {
|
|
197
|
-
$currentRuntime | Add-Member -NotePropertyName "poller_pid" -NotePropertyValue $pollerPid
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if ($dispatcherPid) {
|
|
201
|
-
if ($currentRuntime.PSObject.Properties.Name.Contains("dispatcher_pid")) {
|
|
202
|
-
$currentRuntime.dispatcher_pid = $dispatcherPid
|
|
203
|
-
} else {
|
|
204
|
-
$currentRuntime | Add-Member -NotePropertyName "dispatcher_pid" -NotePropertyValue $dispatcherPid
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if ($responderPid) {
|
|
208
|
-
if ($currentRuntime.PSObject.Properties.Name.Contains("responder_pid")) {
|
|
209
|
-
$currentRuntime.responder_pid = $responderPid
|
|
210
|
-
} else {
|
|
211
|
-
$currentRuntime | Add-Member -NotePropertyName "responder_pid" -NotePropertyValue $responderPid
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if ($envFile["BLUN_TELEGRAM_APP_SERVER_WS_URL"] -and $telegramPluginRoot) {
|
|
217
|
-
try {
|
|
218
|
-
$bootstrapScript = Join-Path $telegramPluginRoot "app-server-cli.js"
|
|
219
|
-
$loaded = & node $bootstrapScript "list-loaded" "--ws-url" $envFile["BLUN_TELEGRAM_APP_SERVER_WS_URL"] | ConvertFrom-Json
|
|
220
|
-
$loadedThreads = @($loaded.data)
|
|
221
|
-
} catch {
|
|
222
|
-
$loadedThreads = @()
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
$result = [ordered]@{
|
|
227
|
-
profile = $profileAgent
|
|
228
|
-
state_dir = $stateDir
|
|
229
|
-
plugin_root = $telegramPluginRoot
|
|
230
|
-
active_ws = $envFile["BLUN_TELEGRAM_APP_SERVER_WS_URL"]
|
|
231
|
-
dispatch_mode = $dispatchMode
|
|
232
|
-
idle_cooldown_ms = $idleCooldownMs
|
|
233
|
-
ambient_queue_ttl_ms = $ambientQueueTtlMs
|
|
182
|
+
"wartet in Queue"
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if ($currentRuntime) {
|
|
186
|
+
if ($stateThreadId) {
|
|
187
|
+
if ($currentRuntime.PSObject.Properties.Name.Contains("thread_id")) {
|
|
188
|
+
$currentRuntime.thread_id = $stateThreadId
|
|
189
|
+
} else {
|
|
190
|
+
$currentRuntime | Add-Member -NotePropertyName "thread_id" -NotePropertyValue $stateThreadId
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if ($pollerPid) {
|
|
194
|
+
if ($currentRuntime.PSObject.Properties.Name.Contains("poller_pid")) {
|
|
195
|
+
$currentRuntime.poller_pid = $pollerPid
|
|
196
|
+
} else {
|
|
197
|
+
$currentRuntime | Add-Member -NotePropertyName "poller_pid" -NotePropertyValue $pollerPid
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if ($dispatcherPid) {
|
|
201
|
+
if ($currentRuntime.PSObject.Properties.Name.Contains("dispatcher_pid")) {
|
|
202
|
+
$currentRuntime.dispatcher_pid = $dispatcherPid
|
|
203
|
+
} else {
|
|
204
|
+
$currentRuntime | Add-Member -NotePropertyName "dispatcher_pid" -NotePropertyValue $dispatcherPid
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if ($responderPid) {
|
|
208
|
+
if ($currentRuntime.PSObject.Properties.Name.Contains("responder_pid")) {
|
|
209
|
+
$currentRuntime.responder_pid = $responderPid
|
|
210
|
+
} else {
|
|
211
|
+
$currentRuntime | Add-Member -NotePropertyName "responder_pid" -NotePropertyValue $responderPid
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if ($envFile["BLUN_TELEGRAM_APP_SERVER_WS_URL"] -and $telegramPluginRoot) {
|
|
217
|
+
try {
|
|
218
|
+
$bootstrapScript = Join-Path $telegramPluginRoot "app-server-cli.js"
|
|
219
|
+
$loaded = & node $bootstrapScript "list-loaded" "--ws-url" $envFile["BLUN_TELEGRAM_APP_SERVER_WS_URL"] | ConvertFrom-Json
|
|
220
|
+
$loadedThreads = @($loaded.data)
|
|
221
|
+
} catch {
|
|
222
|
+
$loadedThreads = @()
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
$result = [ordered]@{
|
|
227
|
+
profile = $profileAgent
|
|
228
|
+
state_dir = $stateDir
|
|
229
|
+
plugin_root = $telegramPluginRoot
|
|
230
|
+
active_ws = $envFile["BLUN_TELEGRAM_APP_SERVER_WS_URL"]
|
|
231
|
+
dispatch_mode = $dispatchMode
|
|
232
|
+
idle_cooldown_ms = $idleCooldownMs
|
|
233
|
+
ambient_queue_ttl_ms = $ambientQueueTtlMs
|
|
234
234
|
pending_reply_timeout_ms = $(if ($envFile["BLUN_TELEGRAM_PENDING_REPLY_TIMEOUT_MS"]) { $envFile["BLUN_TELEGRAM_PENDING_REPLY_TIMEOUT_MS"] } else { "1800000" })
|
|
235
|
-
env_thread_id = $envFile["BLUN_TELEGRAM_THREAD_ID"]
|
|
236
|
-
runtime_thread_id = $runtimeThreadId
|
|
237
|
-
state_thread_id = $stateThreadId
|
|
238
|
-
active_thread_id = if ($runtimeThreadId) { $runtimeThreadId } elseif ($envFile["BLUN_TELEGRAM_THREAD_ID"]) { $envFile["BLUN_TELEGRAM_THREAD_ID"] } else { $stateThreadId }
|
|
239
|
-
frontend_owner_pid = $(if ($currentRuntime -and $currentRuntime.frontend_host_pid) { [string]$currentRuntime.frontend_host_pid } else { "" })
|
|
240
|
-
queue_notifier_pid = $(if ($currentRuntime -and $currentRuntime.queue_notifier_pid) { [string]$currentRuntime.queue_notifier_pid } else { "" })
|
|
241
|
-
current_runtime = $currentRuntime
|
|
242
|
-
loaded_threads = $loadedThreads
|
|
235
|
+
env_thread_id = $envFile["BLUN_TELEGRAM_THREAD_ID"]
|
|
236
|
+
runtime_thread_id = $runtimeThreadId
|
|
237
|
+
state_thread_id = $stateThreadId
|
|
238
|
+
active_thread_id = if ($runtimeThreadId) { $runtimeThreadId } elseif ($envFile["BLUN_TELEGRAM_THREAD_ID"]) { $envFile["BLUN_TELEGRAM_THREAD_ID"] } else { $stateThreadId }
|
|
239
|
+
frontend_owner_pid = $(if ($currentRuntime -and $currentRuntime.frontend_host_pid) { [string]$currentRuntime.frontend_host_pid } else { "" })
|
|
240
|
+
queue_notifier_pid = $(if ($currentRuntime -and $currentRuntime.queue_notifier_pid) { [string]$currentRuntime.queue_notifier_pid } else { "" })
|
|
241
|
+
current_runtime = $currentRuntime
|
|
242
|
+
loaded_threads = $loadedThreads
|
|
243
243
|
queue_depth = $queued.Count
|
|
244
244
|
visible_waiting_depth = ($queued.Count + $pendingReplies.Count)
|
|
245
245
|
direct_queue_depth = $directQueued.Count
|
|
246
|
-
ambient_queue_depth = $ambientQueued.Count
|
|
247
|
-
escalation_queue_depth = $escalationQueued.Count
|
|
248
|
-
parked_queue_depth = $staleAmbientQueued.Count
|
|
249
|
-
submitted_depth = $submitted.Count
|
|
250
|
-
pending_reply_depth = $pendingReplies.Count
|
|
251
|
-
expired_pending_reply_depth = $expiredPendingReplies.Count
|
|
252
|
-
delivered_count = $delivered.Count
|
|
253
|
-
error_count = $errors.Count
|
|
254
|
-
history_count = $queue.Count
|
|
255
|
-
last_inbound = $state.lastInbound
|
|
256
|
-
last_outbound = $state.lastOutbound
|
|
257
|
-
poller_pid = $pollerPid
|
|
258
|
-
dispatcher_pid = $dispatcherPid
|
|
259
|
-
responder_pid = $responderPid
|
|
246
|
+
ambient_queue_depth = $ambientQueued.Count
|
|
247
|
+
escalation_queue_depth = $escalationQueued.Count
|
|
248
|
+
parked_queue_depth = $staleAmbientQueued.Count
|
|
249
|
+
submitted_depth = $submitted.Count
|
|
250
|
+
pending_reply_depth = $pendingReplies.Count
|
|
251
|
+
expired_pending_reply_depth = $expiredPendingReplies.Count
|
|
252
|
+
delivered_count = $delivered.Count
|
|
253
|
+
error_count = $errors.Count
|
|
254
|
+
history_count = $queue.Count
|
|
255
|
+
last_inbound = $state.lastInbound
|
|
256
|
+
last_outbound = $state.lastOutbound
|
|
257
|
+
poller_pid = $pollerPid
|
|
258
|
+
dispatcher_pid = $dispatcherPid
|
|
259
|
+
responder_pid = $responderPid
|
|
260
260
|
next_queued = if ($nextQueued.Count -gt 0) {
|
|
261
|
-
[ordered]@{
|
|
262
|
-
chat_id = $nextQueued[0].chatId
|
|
263
|
-
message_id = $nextQueued[0].messageId
|
|
264
|
-
relevance = $nextQueued[0].relevance
|
|
265
|
-
preview = Normalize-Preview -Value ([string]$nextQueued[0].text)
|
|
266
|
-
}
|
|
261
|
+
[ordered]@{
|
|
262
|
+
chat_id = $nextQueued[0].chatId
|
|
263
|
+
message_id = $nextQueued[0].messageId
|
|
264
|
+
relevance = $nextQueued[0].relevance
|
|
265
|
+
preview = Normalize-Preview -Value ([string]$nextQueued[0].text)
|
|
266
|
+
}
|
|
267
267
|
} else {
|
|
268
268
|
$null
|
|
269
269
|
}
|
|
@@ -279,21 +279,21 @@ $result = [ordered]@{
|
|
|
279
279
|
}
|
|
280
280
|
wait_reason = $waitReason
|
|
281
281
|
}
|
|
282
|
-
|
|
283
|
-
if ($result.poller_pid) {
|
|
284
|
-
$result["poller_alive"] = Test-PidAlive -ProcId ([int]$result.poller_pid)
|
|
285
|
-
}
|
|
286
|
-
if ($result.dispatcher_pid) {
|
|
287
|
-
$result["dispatcher_alive"] = Test-PidAlive -ProcId ([int]$result.dispatcher_pid)
|
|
288
|
-
}
|
|
289
|
-
if ($result.responder_pid) {
|
|
290
|
-
$result["responder_alive"] = Test-PidAlive -ProcId ([int]$result.responder_pid)
|
|
291
|
-
}
|
|
292
|
-
if ($result.frontend_owner_pid) {
|
|
293
|
-
$result["frontend_owner_alive"] = Test-PidAlive -ProcId ([int]$result.frontend_owner_pid)
|
|
294
|
-
}
|
|
295
|
-
if ($result.queue_notifier_pid) {
|
|
296
|
-
$result["queue_notifier_alive"] = Test-PidAlive -ProcId ([int]$result.queue_notifier_pid)
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
$result | ConvertTo-Json -Depth 8
|
|
282
|
+
|
|
283
|
+
if ($result.poller_pid) {
|
|
284
|
+
$result["poller_alive"] = Test-PidAlive -ProcId ([int]$result.poller_pid)
|
|
285
|
+
}
|
|
286
|
+
if ($result.dispatcher_pid) {
|
|
287
|
+
$result["dispatcher_alive"] = Test-PidAlive -ProcId ([int]$result.dispatcher_pid)
|
|
288
|
+
}
|
|
289
|
+
if ($result.responder_pid) {
|
|
290
|
+
$result["responder_alive"] = Test-PidAlive -ProcId ([int]$result.responder_pid)
|
|
291
|
+
}
|
|
292
|
+
if ($result.frontend_owner_pid) {
|
|
293
|
+
$result["frontend_owner_alive"] = Test-PidAlive -ProcId ([int]$result.frontend_owner_pid)
|
|
294
|
+
}
|
|
295
|
+
if ($result.queue_notifier_pid) {
|
|
296
|
+
$result["queue_notifier_alive"] = Test-PidAlive -ProcId ([int]$result.queue_notifier_pid)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
$result | ConvertTo-Json -Depth 8
|