@ai-wendao/ant 0.5.1 → 0.5.3

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.
Files changed (2) hide show
  1. package/client.js +65 -22
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -183,19 +183,40 @@ window.__ModuleLoader__.load({
183
183
  return normalized ? new URL('/console', normalized).toString() : null
184
184
  }
185
185
  const versionParts = (value) => {
186
- if (typeof value !== 'string' || !/^\d+\.\d+\.\d+$/u.test(value)) return null
187
- return value.split('.')
186
+ if (typeof value !== 'string') return null
187
+ const match = /^(\d+)\.(\d+)\.(\d+)(?:-((?:0|[1-9]\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u.exec(value)
188
+ if (!match) return null
189
+ return { core: match.slice(1, 4), prerelease: match[4]?.split('.') ?? null }
190
+ }
191
+ const compareNumericVersionIdentifiers = (left, right) => {
192
+ const normalizedLeft = left.replace(/^0+(?=\d)/u, '')
193
+ const normalizedRight = right.replace(/^0+(?=\d)/u, '')
194
+ if (normalizedLeft.length !== normalizedRight.length) return normalizedLeft.length < normalizedRight.length ? -1 : 1
195
+ return normalizedLeft === normalizedRight ? 0 : normalizedLeft < normalizedRight ? -1 : 1
188
196
  }
189
197
  const newerVersion = (candidate, current) => {
190
198
  const next = versionParts(candidate)
191
199
  const installed = versionParts(current)
192
200
  if (!next || !installed) return false
193
- for (let index = 0; index < next.length; index += 1) {
194
- if (next[index] !== installed[index]) {
195
- return next[index].length === installed[index].length
196
- ? next[index] > installed[index]
197
- : next[index].length > installed[index].length
198
- }
201
+ for (let index = 0; index < next.core.length; index += 1) {
202
+ const order = compareNumericVersionIdentifiers(next.core[index], installed.core[index])
203
+ if (order !== 0) return order > 0
204
+ }
205
+ if (!next.prerelease) return Boolean(installed.prerelease)
206
+ if (!installed.prerelease) return false
207
+ for (let index = 0; index < Math.max(next.prerelease.length, installed.prerelease.length); index += 1) {
208
+ const nextIdentifier = next.prerelease[index]
209
+ const installedIdentifier = installed.prerelease[index]
210
+ if (nextIdentifier === undefined) return false
211
+ if (installedIdentifier === undefined) return true
212
+ if (nextIdentifier === installedIdentifier) continue
213
+ const nextIsNumeric = /^\d+$/u.test(nextIdentifier)
214
+ const installedIsNumeric = /^\d+$/u.test(installedIdentifier)
215
+ if (nextIsNumeric && installedIsNumeric) {
216
+ return compareNumericVersionIdentifiers(nextIdentifier, installedIdentifier) > 0
217
+ }
218
+ if (nextIsNumeric !== installedIsNumeric) return !nextIsNumeric
219
+ return nextIdentifier > installedIdentifier
199
220
  }
200
221
  return false
201
222
  }
@@ -3099,6 +3120,9 @@ window.__ModuleLoader__.load({
3099
3120
  const originalHeadlines = new Map()
3100
3121
  let headlineObserver = null
3101
3122
  let applied = null
3123
+ let timer = null
3124
+ let retryTimer = null
3125
+ let disposed = false
3102
3126
  const isHeroHeadlineNode = (node) => {
3103
3127
  let container = node?.parentElement
3104
3128
  const compact = (value) => value?.replace(/\s+/gu, '') || ''
@@ -3121,7 +3145,7 @@ window.__ModuleLoader__.load({
3121
3145
  slotDisposers.get(name)?.()
3122
3146
  slotDisposers.delete(name); slotValues.delete(name)
3123
3147
  if (!value) return
3124
- const dispose = ctx.slots.inject(name, () => ctx.slots.register({ name }, component))
3148
+ const dispose = ctx.slots.inject(name, () => ctx.slots.register({ name, priority: -1 }, component))
3125
3149
  slotDisposers.set(name, dispose); slotValues.set(name, value)
3126
3150
  }
3127
3151
  const replaceHeadlineNode = (node) => {
@@ -3147,6 +3171,15 @@ window.__ModuleLoader__.load({
3147
3171
  }
3148
3172
  const updateHeadline = (records = null) => {
3149
3173
  if (typeof document === 'undefined' || !document.body) return
3174
+ if (!applied?.headline) {
3175
+ for (const [node, prior] of originalHeadlines) {
3176
+ if (node.textContent?.trim() === prior.current) {
3177
+ node.textContent = prior.original
3178
+ originalHeadlines.delete(node)
3179
+ }
3180
+ }
3181
+ return
3182
+ }
3150
3183
  if (!records) { replaceHeadlineSubtree(document.body); return }
3151
3184
  for (const record of records) {
3152
3185
  if (record.type === 'characterData') replaceHeadlineNode(record.target)
@@ -3156,7 +3189,6 @@ window.__ModuleLoader__.load({
3156
3189
  }
3157
3190
  const apply = (value) => {
3158
3191
  const branding = normalizeBranding(value)
3159
- const previousHeadline = applied?.headline
3160
3192
  applied = branding ? { ...branding } : null
3161
3193
  const logo = branding?.logo_data_url || null
3162
3194
  const nameValue = branding && (branding.wordmark || branding.badge)
@@ -3177,11 +3209,29 @@ window.__ModuleLoader__.load({
3177
3209
  }
3178
3210
  updateHeadline()
3179
3211
  }
3180
- apply(readBrandingCache())
3212
+
3213
+ const cleanup = () => {
3214
+ if (disposed) return
3215
+ disposed = true
3216
+ if (timer !== null) clearInterval(timer)
3217
+ if (retryTimer !== null) clearTimeout(retryTimer)
3218
+ headlineObserver?.disconnect()
3219
+ for (const [node, prior] of originalHeadlines) {
3220
+ if (node.textContent?.trim() === prior.current) node.textContent = prior.original
3221
+ }
3222
+ for (const dispose of slotDisposers.values()) dispose?.()
3223
+ }
3224
+
3225
+ try {
3226
+ apply(readBrandingCache())
3227
+ } catch (error) {
3228
+ cleanup()
3229
+ console.warn('ANT branding setup failed; continuing with the default DSH branding.', error)
3230
+ return cleanup
3231
+ }
3232
+
3181
3233
  let etag = applied?.revision ? `"${applied.revision}"` : null
3182
3234
  let retryCount = 0
3183
- let retryTimer = null
3184
- let disposed = false
3185
3235
  const refresh = async () => {
3186
3236
  if (disposed) return
3187
3237
  let retryable = true
@@ -3223,15 +3273,8 @@ window.__ModuleLoader__.load({
3223
3273
  }
3224
3274
  }
3225
3275
  void refresh()
3226
- const timer = setInterval(() => void refresh(), 5 * 60 * 1000)
3227
- return () => {
3228
- disposed = true
3229
- clearInterval(timer); clearTimeout(retryTimer); headlineObserver?.disconnect()
3230
- for (const [node, prior] of originalHeadlines) {
3231
- if (node.textContent?.trim() === prior.current) node.textContent = prior.original
3232
- }
3233
- for (const dispose of slotDisposers.values()) dispose?.()
3234
- }
3276
+ timer = setInterval(() => void refresh(), 5 * 60 * 1000)
3277
+ return cleanup
3235
3278
  }
3236
3279
 
3237
3280
  function apply(ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-wendao/ant",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "ANT (AI-native Teams) connects a DeepSeek Harness Desktop profile to team identity and approved models.",
5
5
  "type": "module",
6
6
  "scripts": {