clanka 0.16.0 → 0.16.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "clanka",
3
3
  "type": "module",
4
- "version": "0.16.0",
4
+ "version": "0.16.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -109,18 +109,18 @@ const apiJson = {
109
109
  }
110
110
 
111
111
  const catalog = [
112
- new ModelsRepo.ModelInfo({
113
- provider: "openai",
114
- id: "gpt-6-astra",
115
- name: "GPT-6 Astra",
116
- efforts: ["low", "medium", "high", "xhigh", "max"],
117
- }),
118
112
  new ModelsRepo.ModelInfo({
119
113
  provider: "copilot",
120
114
  id: "claude-fable-5.1",
121
115
  name: "Claude Fable 5.1",
122
116
  efforts: ["low", "high"],
123
117
  }),
118
+ new ModelsRepo.ModelInfo({
119
+ provider: "openai",
120
+ id: "gpt-6-astra",
121
+ name: "GPT-6 Astra",
122
+ efforts: ["low", "medium", "high", "xhigh", "max"],
123
+ }),
124
124
  new ModelsRepo.ModelInfo({
125
125
  provider: "xai",
126
126
  id: "grok-4.6",
@@ -183,6 +183,54 @@ describe("ModelsRepo.layerModelsDev", () => {
183
183
  }).pipe(Effect.provide(KeyValueStore.layerMemory)),
184
184
  )
185
185
 
186
+ it.effect("keeps the 10 newest models, breaking date ties by name", () =>
187
+ Effect.gen(function* () {
188
+ const models = Object.fromEntries(
189
+ [
190
+ ["oldest", "Alpha old", "2020-01-01"],
191
+ ["undated-z", "Zulu undated"],
192
+ ["first-tie", "Zulu tie", "2026-06-01"],
193
+ ["march", "Gamma", "2026-03-01"],
194
+ ["newest", "Zulu newest", "2026-10-01"],
195
+ ["january", "Delta", "2026-01-01"],
196
+ ["undated-a", "Alpha undated"],
197
+ ["december", "Epsilon", "2025-12-01"],
198
+ ["second-tie", "Alpha tie", "2026-06-01"],
199
+ ["november", "Eta", "2025-11-01"],
200
+ ["older", "Theta", "2024-01-01"],
201
+ ].map(([id, name, release_date]) => [
202
+ id,
203
+ { id, name, release_date, tool_call: true },
204
+ ]),
205
+ )
206
+ const client = HttpClient.make((request) =>
207
+ Effect.succeed(
208
+ HttpClientResponse.fromWeb(
209
+ request,
210
+ new Response(JSON.stringify({ openai: { models } }), {
211
+ headers: { "content-type": "application/json" },
212
+ }),
213
+ ),
214
+ ),
215
+ )
216
+ assert.deepStrictEqual(
217
+ (yield* modelsWith(client)).map((model) => model.id),
218
+ [
219
+ "newest",
220
+ "second-tie",
221
+ "first-tie",
222
+ "march",
223
+ "january",
224
+ "december",
225
+ "november",
226
+ "older",
227
+ "oldest",
228
+ "undated-a",
229
+ ],
230
+ )
231
+ }).pipe(Effect.provide(KeyValueStore.layerMemory)),
232
+ )
233
+
186
234
  it.effect("serves an expired cached catalog when the refresh fails", () =>
187
235
  Effect.gen(function* () {
188
236
  yield* modelsWith(online)
package/src/ModelsRepo.ts CHANGED
@@ -84,6 +84,7 @@ const ModelsDevModel = Schema.Struct({
84
84
  id: Schema.String,
85
85
  name: Schema.String,
86
86
  type: Schema.optionalKey(Schema.String),
87
+ release_date: Schema.optionalKey(Schema.String),
87
88
  status: Schema.optionalKey(Schema.String),
88
89
  tool_call: Schema.optionalKey(Schema.Boolean),
89
90
  reasoning_options: Schema.optionalKey(
@@ -100,7 +101,7 @@ const ModelsDevProvider = Schema.Struct({
100
101
  models: Schema.Record(Schema.String, Schema.Unknown),
101
102
  })
102
103
 
103
- // models.dev provider id to clanka provider, in catalog order.
104
+ // models.dev provider id to clanka provider.
104
105
  const providerIds: ReadonlyArray<readonly [string, Provider]> = [
105
106
  ["openai", "openai"],
106
107
  ["github-copilot", "copilot"],
@@ -117,30 +118,38 @@ const decodeModel = Schema.decodeUnknownOption(ModelsDevModel)
117
118
  const isThoughtLevel = Schema.is(ThoughtLevel)
118
119
 
119
120
  const toCatalog = (api: typeof ModelsDevApi.Type): ReadonlyArray<ModelInfo> =>
120
- providerIds.flatMap(([id, provider]) =>
121
- Object.values(api[id]?.models ?? {}).flatMap((entry) => {
122
- const model = Option.getOrUndefined(decodeModel(entry))
123
- if (
124
- model === undefined ||
125
- model.type !== undefined ||
126
- model.status === "deprecated" ||
127
- model.tool_call !== true
128
- ) {
129
- return []
130
- }
121
+ providerIds
122
+ .flatMap(([id, provider]) =>
123
+ Object.values(api[id]?.models ?? {}).flatMap((entry) => {
124
+ const model = Option.getOrUndefined(decodeModel(entry))
125
+ if (
126
+ model === undefined ||
127
+ model.type !== undefined ||
128
+ model.status === "deprecated" ||
129
+ model.tool_call !== true
130
+ ) {
131
+ return []
132
+ }
133
+ return [{ ...model, provider }]
134
+ }),
135
+ )
136
+ .toSorted(
137
+ (a, b) =>
138
+ (b.release_date ?? "").localeCompare(a.release_date ?? "") ||
139
+ a.name.localeCompare(b.name),
140
+ )
141
+ .slice(0, 10)
142
+ .map((model) => {
131
143
  const effort = model.reasoning_options?.find(
132
144
  (option) => option.type === "effort",
133
145
  )
134
- return [
135
- new ModelInfo({
136
- provider,
137
- id: model.id,
138
- name: model.name,
139
- efforts: (effort?.values ?? []).filter(isThoughtLevel),
140
- }),
141
- ]
142
- }),
143
- )
146
+ return new ModelInfo({
147
+ provider: model.provider,
148
+ id: model.id,
149
+ name: model.name,
150
+ efforts: (effort?.values ?? []).filter(isThoughtLevel),
151
+ })
152
+ })
144
153
 
145
154
  class CachedCatalog extends Schema.Class<CachedCatalog>(
146
155
  "clanka/ModelsRepo/CachedCatalog",
@@ -177,7 +186,9 @@ export class ModelsRepo extends Context.Service<
177
186
  /**
178
187
  * The catalog built from `https://models.dev/api.json`: the `openai`,
179
188
  * `github-copilot` and `xai` text models that are not deprecated and accept
180
- * tool calls, cached in the `KeyValueStore` for `ttl` (default 24 hours).
189
+ * tool calls. Keeps the 10 newest models by release date, then name
190
+ * alphabetically, with undated models last. Cached in the `KeyValueStore`
191
+ * for `ttl` (default 24 hours).
181
192
  * Serves the cached catalog when the fetch fails, then `fallback`.
182
193
  *
183
194
  * @since 1.0.0