@aiwayds/dsh-model-sync 0.12.1 → 0.13.1

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 (88) hide show
  1. package/README.md +18 -17
  2. package/README.zh-CN.md +18 -17
  3. package/lib/index.d.ts +54 -384
  4. package/lib/index.js +306 -1107
  5. package/lib/index.js.map +1 -1
  6. package/lib/official-adapter.d.ts +80 -0
  7. package/lib/official-adapter.js +34 -0
  8. package/lib/official-adapter.js.map +1 -0
  9. package/lib/official-migrate.d.ts +122 -0
  10. package/lib/official-migrate.js +653 -0
  11. package/lib/official-migrate.js.map +1 -0
  12. package/lib/official-scheduler.d.ts +72 -0
  13. package/lib/official-scheduler.js +195 -0
  14. package/lib/official-scheduler.js.map +1 -0
  15. package/lib/official-store.d.ts +41 -0
  16. package/lib/official-store.js +84 -0
  17. package/lib/official-store.js.map +1 -0
  18. package/lib/official-sync.d.ts +68 -0
  19. package/lib/official-sync.js +274 -0
  20. package/lib/official-sync.js.map +1 -0
  21. package/lib/opencode-go-adapter.d.ts +56 -0
  22. package/lib/opencode-go-adapter.js +455 -0
  23. package/lib/opencode-go-adapter.js.map +1 -0
  24. package/lib/opencode-go-patch-file.d.ts +11 -0
  25. package/lib/opencode-go-patch-file.js +175 -11
  26. package/lib/opencode-go-patch-file.js.map +1 -1
  27. package/lib/opencode-go-source.d.ts +1 -1
  28. package/lib/opencode-go-source.js +1 -1
  29. package/locale/en.json +1 -1
  30. package/locale/zh.json +1 -1
  31. package/package.json +3 -3
  32. package/src/index.ts +352 -1281
  33. package/src/official-adapter.ts +111 -0
  34. package/src/official-migrate.ts +863 -0
  35. package/src/official-scheduler.ts +235 -0
  36. package/src/official-store.ts +122 -0
  37. package/src/official-sync.ts +371 -0
  38. package/src/opencode-go-adapter.ts +494 -0
  39. package/src/opencode-go-patch-file.ts +175 -9
  40. package/src/opencode-go-source.ts +1 -1
  41. package/lib/opencode-go-diagnose.d.ts +0 -96
  42. package/lib/opencode-go-diagnose.js +0 -177
  43. package/lib/opencode-go-diagnose.js.map +0 -1
  44. package/lib/opencode-go-grouping.d.ts +0 -7
  45. package/lib/opencode-go-grouping.js +0 -21
  46. package/lib/opencode-go-grouping.js.map +0 -1
  47. package/lib/opencode-go-host-catalog.d.ts +0 -42
  48. package/lib/opencode-go-host-catalog.js +0 -98
  49. package/lib/opencode-go-host-catalog.js.map +0 -1
  50. package/lib/opencode-go-journal.d.ts +0 -114
  51. package/lib/opencode-go-journal.js +0 -406
  52. package/lib/opencode-go-journal.js.map +0 -1
  53. package/lib/opencode-go-migrate.d.ts +0 -378
  54. package/lib/opencode-go-migrate.js +0 -1529
  55. package/lib/opencode-go-migrate.js.map +0 -1
  56. package/lib/opencode-go-migration.d.ts +0 -270
  57. package/lib/opencode-go-migration.js +0 -473
  58. package/lib/opencode-go-migration.js.map +0 -1
  59. package/lib/opencode-go-one-shot.d.ts +0 -282
  60. package/lib/opencode-go-one-shot.js +0 -1131
  61. package/lib/opencode-go-one-shot.js.map +0 -1
  62. package/lib/opencode-go-planner.d.ts +0 -168
  63. package/lib/opencode-go-planner.js +0 -407
  64. package/lib/opencode-go-planner.js.map +0 -1
  65. package/lib/opencode-go-scheduler.d.ts +0 -128
  66. package/lib/opencode-go-scheduler.js +0 -241
  67. package/lib/opencode-go-scheduler.js.map +0 -1
  68. package/lib/opencode-go-store.d.ts +0 -18
  69. package/lib/opencode-go-store.js +0 -68
  70. package/lib/opencode-go-store.js.map +0 -1
  71. package/lib/opencode-go-sync.d.ts +0 -107
  72. package/lib/opencode-go-sync.js +0 -388
  73. package/lib/opencode-go-sync.js.map +0 -1
  74. package/lib/opencode-go-writer.d.ts +0 -148
  75. package/lib/opencode-go-writer.js +0 -1061
  76. package/lib/opencode-go-writer.js.map +0 -1
  77. package/src/opencode-go-diagnose.ts +0 -276
  78. package/src/opencode-go-grouping.ts +0 -26
  79. package/src/opencode-go-host-catalog.ts +0 -125
  80. package/src/opencode-go-journal.ts +0 -460
  81. package/src/opencode-go-migrate.ts +0 -1951
  82. package/src/opencode-go-migration.ts +0 -666
  83. package/src/opencode-go-one-shot.ts +0 -1399
  84. package/src/opencode-go-planner.ts +0 -582
  85. package/src/opencode-go-scheduler.ts +0 -315
  86. package/src/opencode-go-store.ts +0 -73
  87. package/src/opencode-go-sync.ts +0 -541
  88. package/src/opencode-go-writer.ts +0 -1301
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Generic Upstream Provider Adapter contract and registry for Official Sync.
3
+ *
4
+ * Supported vendors expose an authoritative models API that is mapped into
5
+ * per-protocol Managed Custom Providers, detached from pi-ai's built-in
6
+ * catalog. Providers without an adapter explicitly report unsupported on
7
+ * official sync or migration commands while continuing to use pi.dev on bare
8
+ * `/model-sync`.
9
+ *
10
+ * @module dsh-model-sync/official-adapter
11
+ */
12
+
13
+ import type { SettingsModelProfile } from './translate.ts'
14
+ import type { GoAuthStatus, GoFailureKind, GoFetchLike } from './opencode-go-source.ts'
15
+ import { opencodeGoAdapter } from './opencode-go-adapter.ts'
16
+
17
+ export type SessionHeaderMode = 'auto' | 'static' | 'none'
18
+
19
+ export interface OfficialAdapterConfig {
20
+ intervalMinutes: number
21
+ modelsUrl: string
22
+ sessionHeader: SessionHeaderMode
23
+ routes: Record<string, string>
24
+ }
25
+
26
+ export interface CustomProviderSpec {
27
+ slot: string
28
+ routeId: string
29
+ displayName: string
30
+ api: string
31
+ baseURL: string
32
+ apiKeyEnv: string
33
+ models: SettingsModelProfile[]
34
+ compat?: Record<string, unknown>
35
+ headers?: Record<string, string>
36
+ }
37
+
38
+ export interface OfficialFetchResult {
39
+ ok: boolean
40
+ providers: CustomProviderSpec[]
41
+ activeSlots: string[]
42
+ emptySlots: string[]
43
+ warnings: string[]
44
+ authStatus: GoAuthStatus
45
+ failureKind?: GoFailureKind
46
+ error?: {
47
+ kind: GoFailureKind
48
+ status?: number
49
+ message: string
50
+ }
51
+ observedAt: number
52
+ totalModels: number
53
+ sessionHeaderApplied: boolean
54
+ hostNativeSessionHeader: boolean
55
+ }
56
+
57
+ export type CompatHintsByProtocol = Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, unknown>>>>>>
58
+
59
+ export interface OfficialFetchOptions {
60
+ apiKey: string
61
+ apiKeyEnv: string
62
+ config: OfficialAdapterConfig
63
+ timeoutMs?: number
64
+ signal?: AbortSignal
65
+ fetchImpl?: GoFetchLike
66
+ /** Test seam: override host native `x-opencode-session` detection. */
67
+ detectHostSessionHeader?: () => boolean
68
+ /** Test seam: override pi-ai compat hints lookup. */
69
+ loadPiAiCompatHints?: () => CompatHintsByProtocol
70
+ }
71
+
72
+ export interface UpstreamProviderAdapter {
73
+ readonly id: string
74
+ readonly aliases: readonly string[]
75
+ readonly builtinProviderId: string
76
+ readonly displayName: string
77
+ readonly defaultIntervalMinutes: number
78
+ readonly defaultModelsUrl: string
79
+ readonly defaultKeyRefs: readonly string[]
80
+ readonly slotOrder: readonly string[]
81
+ readonly defaultSlotRoutes: Readonly<Record<string, string>>
82
+ readonly legacyExtraRoutes: readonly string[]
83
+ detectHostSessionHeader?(): boolean
84
+ fetchAndPlan(options: OfficialFetchOptions): Promise<OfficialFetchResult>
85
+ }
86
+
87
+ export const OFFICIAL_ADAPTERS: readonly UpstreamProviderAdapter[] = [
88
+ opencodeGoAdapter,
89
+ ]
90
+
91
+ export function listOfficialAdapters(): readonly UpstreamProviderAdapter[] {
92
+ return OFFICIAL_ADAPTERS
93
+ }
94
+
95
+ export function resolveOfficialAdapter(input: string): UpstreamProviderAdapter | undefined {
96
+ const normalized = input.trim().toLowerCase()
97
+ if (normalized === '') return undefined
98
+ return OFFICIAL_ADAPTERS.find((adapter) =>
99
+ adapter.id.toLowerCase() === normalized
100
+ || adapter.aliases.some((alias) => alias.toLowerCase() === normalized),
101
+ )
102
+ }
103
+
104
+ export function formatUnsupportedProviderError(providerName: string): string {
105
+ const supported = OFFICIAL_ADAPTERS.map((a) => `${a.id} (${a.aliases.join(' / ')})`).join(', ')
106
+ return [
107
+ `Provider "${providerName}" is not supported for official models API sync or migration yet.`,
108
+ `Currently supported: ${supported}.`,
109
+ 'Other providers continue to sync from pi.dev via bare `/model-sync`.',
110
+ ].join(' ')
111
+ }