pi-requesty-discover 1.1.0 → 1.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-requesty-discover",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Discover available Requesty models for the Pi Coding Agent",
5
5
  "repository": {
6
6
  "type": "git",
@@ -2,6 +2,7 @@ import type { ProviderModelConfig } from '@earendil-works/pi-coding-agent'
2
2
  import fs from 'node:fs'
3
3
  import path from 'node:path'
4
4
  import { getEnv, type Env } from './env'
5
+ import { formatModelsDiffSummary, type ModelsDiff } from './models-json'
5
6
 
6
7
  const HEALTH_CHECK_CONCURRENCY = 10
7
8
  const HEALTH_CHECK_TIMEOUT_MS = 15_000
@@ -98,7 +99,12 @@ export function formatHealthSummary(results: HealthCheckResult[]): string {
98
99
  return `Health check: ${passed.length} OK, ${failed.length} failed:\n${failedModels}\n`
99
100
  }
100
101
 
101
- export function writeHealthCheckLog(provider: Provider, results: HealthCheckResult[], envConfig: Env = getEnv()): void {
102
+ export function writeHealthCheckLog(
103
+ provider: Provider,
104
+ results: HealthCheckResult[],
105
+ diff: ModelsDiff,
106
+ envConfig: Env = getEnv(),
107
+ ): void {
102
108
  const passed = results.filter(r => r.ok)
103
109
  const failed = results.filter(r => !r.ok)
104
110
  const lines = [
@@ -110,6 +116,8 @@ export function writeHealthCheckLog(provider: Provider, results: HealthCheckResu
110
116
  `Passed: ${passed.length}`,
111
117
  `Failed: ${failed.length}`,
112
118
  '',
119
+ formatModelsDiffSummary(diff),
120
+ '',
113
121
  ]
114
122
 
115
123
  if (failed.length === 0) {
package/src/index.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { ExtensionAPI, ExtensionCommandContext, ProviderModelConfig } from '@earendil-works/pi-coding-agent'
2
2
  import { getEnv } from './env'
3
- import { getRequestyConfig, updateModelsJson } from './models-json'
3
+ import {
4
+ diffModels,
5
+ formatModelsDiffSummary,
6
+ getRequestyConfig,
7
+ updateModelsJson,
8
+ type ModelsDiff,
9
+ } from './models-json'
4
10
  import { discoverModels } from './requesty-api'
5
11
  import { checkModels, formatHealthSummary, writeHealthCheckLog } from './health-check'
6
12
  import { RequestyStatusLoader } from './ui/requesty-status-loader.ts'
@@ -67,10 +73,11 @@ export async function runCommand(args: string, status: StatusReporter, notifier:
67
73
 
68
74
  try {
69
75
  const env = getEnv()
70
- const { data, provider } = getRequestyConfig(env)
76
+ const { data, provider, existingModelIds } = getRequestyConfig(env)
71
77
  const models = await discoverModels(provider)
72
78
  const modelsMap = new Map(models.map(m => [m.id, m]))
73
79
 
80
+ let diff: ModelsDiff
74
81
  let failed = []
75
82
  let passing: ProviderModelConfig[]
76
83
  let logNote = ''
@@ -89,11 +96,13 @@ export async function runCommand(args: string, status: StatusReporter, notifier:
89
96
  const model = modelsMap.get(r.modelId)
90
97
  return r.ok && model ? [model] : []
91
98
  })
99
+ diff = diffModels(existingModelIds, passing)
92
100
  healthCheckSummary = formatHealthSummary(sortedResults)
93
- writeHealthCheckLog(provider, sortedResults, env)
101
+ writeHealthCheckLog(provider, sortedResults, diff, env)
94
102
  logNote = `Full health check log: ${env.health_check_log_path}\n`
95
103
  } else {
96
104
  passing = models
105
+ diff = diffModels(existingModelIds, passing)
97
106
  }
98
107
 
99
108
  const shouldUpdate = passing.length > 0 && !dryRun
@@ -102,7 +111,7 @@ export async function runCommand(args: string, status: StatusReporter, notifier:
102
111
  }
103
112
 
104
113
  const writeNote = shouldUpdate ? 'Run /reload to use models.json changes.' : 'models.json was not updated.'
105
- const message = `Discovered ${models.length} Requesty model(s).\n${healthCheckSummary}${logNote}${writeNote}`
114
+ const message = `Discovered ${models.length} Requesty model(s).\n${healthCheckSummary}${formatModelsDiffSummary(diff)}\n${logNote}${writeNote}`
106
115
 
107
116
  if (failed.length === 0) {
108
117
  notifier.notify(message, 'info')
@@ -12,6 +12,7 @@ const ProviderSchema = z
12
12
  name: z.string().optional(),
13
13
  baseUrl: z.string().optional(),
14
14
  apiKey: z.string().optional(),
15
+ models: z.array(z.object({ id: z.string() }).catchall(z.unknown())).optional(),
15
16
  })
16
17
  .catchall(z.unknown())
17
18
 
@@ -33,6 +34,12 @@ type RequestyProvider = ModelsJsonProvider & {
33
34
  type RequestyConfig = {
34
35
  data: ModelsJson
35
36
  provider: RequestyProvider
37
+ existingModelIds: string[]
38
+ }
39
+
40
+ export type ModelsDiff = {
41
+ added: string[]
42
+ removed: string[]
36
43
  }
37
44
 
38
45
  export function getRequestyConfig(envConfig: Env = getEnv()): RequestyConfig {
@@ -46,6 +53,7 @@ export function getRequestyConfig(envConfig: Env = getEnv()): RequestyConfig {
46
53
  const apiKey = envConfig.requesty_api_key
47
54
  return {
48
55
  data,
56
+ existingModelIds: (provider.models ?? []).map(m => m.id),
49
57
  provider: {
50
58
  ...provider,
51
59
  name: nonEmptyString(provider.name) ?? DEFAULT_NAME,
@@ -55,6 +63,24 @@ export function getRequestyConfig(envConfig: Env = getEnv()): RequestyConfig {
55
63
  }
56
64
  }
57
65
 
66
+ export function diffModels(previousIds: string[], nextModels: ProviderModelConfig[]): ModelsDiff {
67
+ const previous = new Set(previousIds)
68
+ const next = new Set(nextModels.map(m => m.id))
69
+ return {
70
+ added: [...next].filter(id => !previous.has(id)).toSorted(),
71
+ removed: [...previous].filter(id => !next.has(id)).toSorted(),
72
+ }
73
+ }
74
+
75
+ export function formatModelsDiffSummary(diff: ModelsDiff): string {
76
+ return [
77
+ diff.added.length === 0 ? 'No added models.' : 'Added models:',
78
+ ...diff.added.map(id => `- ${id}`),
79
+ diff.removed.length === 0 ? 'No removed models.' : 'Removed models:',
80
+ ...diff.removed.map(id => `- ${id}`),
81
+ ].join('\n')
82
+ }
83
+
58
84
  export function updateModelsJson(data: ModelsJson, models: ProviderModelConfig[], envConfig: Env = getEnv()): void {
59
85
  const provider = data.providers[envConfig.provider_id]
60
86
  data.providers[envConfig.provider_id] = {