@aiwayds/dsh-model-sync 0.12.0 → 0.13.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.
Files changed (84) hide show
  1. package/README.md +18 -17
  2. package/README.zh-CN.md +18 -17
  3. package/lib/index.d.ts +54 -376
  4. package/lib/index.js +305 -1049
  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 +116 -0
  10. package/lib/official-migrate.js +643 -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 +351 -1214
  33. package/src/official-adapter.ts +111 -0
  34. package/src/official-migrate.ts +840 -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 -75
  42. package/lib/opencode-go-diagnose.js +0 -146
  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-journal.d.ts +0 -110
  48. package/lib/opencode-go-journal.js +0 -406
  49. package/lib/opencode-go-journal.js.map +0 -1
  50. package/lib/opencode-go-migrate.d.ts +0 -345
  51. package/lib/opencode-go-migrate.js +0 -1371
  52. package/lib/opencode-go-migrate.js.map +0 -1
  53. package/lib/opencode-go-migration.d.ts +0 -227
  54. package/lib/opencode-go-migration.js +0 -384
  55. package/lib/opencode-go-migration.js.map +0 -1
  56. package/lib/opencode-go-one-shot.d.ts +0 -276
  57. package/lib/opencode-go-one-shot.js +0 -1096
  58. package/lib/opencode-go-one-shot.js.map +0 -1
  59. package/lib/opencode-go-planner.d.ts +0 -154
  60. package/lib/opencode-go-planner.js +0 -305
  61. package/lib/opencode-go-planner.js.map +0 -1
  62. package/lib/opencode-go-scheduler.d.ts +0 -128
  63. package/lib/opencode-go-scheduler.js +0 -241
  64. package/lib/opencode-go-scheduler.js.map +0 -1
  65. package/lib/opencode-go-store.d.ts +0 -18
  66. package/lib/opencode-go-store.js +0 -68
  67. package/lib/opencode-go-store.js.map +0 -1
  68. package/lib/opencode-go-sync.d.ts +0 -94
  69. package/lib/opencode-go-sync.js +0 -364
  70. package/lib/opencode-go-sync.js.map +0 -1
  71. package/lib/opencode-go-writer.d.ts +0 -132
  72. package/lib/opencode-go-writer.js +0 -977
  73. package/lib/opencode-go-writer.js.map +0 -1
  74. package/src/opencode-go-diagnose.ts +0 -223
  75. package/src/opencode-go-grouping.ts +0 -26
  76. package/src/opencode-go-journal.ts +0 -458
  77. package/src/opencode-go-migrate.ts +0 -1764
  78. package/src/opencode-go-migration.ts +0 -552
  79. package/src/opencode-go-one-shot.ts +0 -1356
  80. package/src/opencode-go-planner.ts +0 -472
  81. package/src/opencode-go-scheduler.ts +0 -315
  82. package/src/opencode-go-store.ts +0 -73
  83. package/src/opencode-go-sync.ts +0 -503
  84. package/src/opencode-go-writer.ts +0 -1201
@@ -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
+ }