clanka 0.12.3 → 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.
- package/dist/Acp.d.ts +9 -0
- package/dist/Acp.d.ts.map +1 -1
- package/dist/Acp.js +21 -10
- package/dist/Acp.js.map +1 -1
- package/dist/Acp.test.js +17 -2
- package/dist/Acp.test.js.map +1 -1
- package/dist/Codex.d.ts +12 -2
- package/dist/Codex.d.ts.map +1 -1
- package/dist/Codex.js +7 -5
- package/dist/Codex.js.map +1 -1
- package/dist/Codex.test.d.ts +2 -0
- package/dist/Codex.test.d.ts.map +1 -0
- package/dist/Codex.test.js +37 -0
- package/dist/Codex.test.js.map +1 -0
- package/dist/Copilot.d.ts.map +1 -1
- package/dist/Copilot.js +4 -4
- package/dist/Copilot.js.map +1 -1
- package/dist/Copilot.test.d.ts +2 -0
- package/dist/Copilot.test.d.ts.map +1 -0
- package/dist/Copilot.test.js +32 -0
- package/dist/Copilot.test.js.map +1 -0
- package/dist/ModelLayer.d.ts +64 -0
- package/dist/ModelLayer.d.ts.map +1 -0
- package/dist/ModelLayer.js +96 -0
- package/dist/ModelLayer.js.map +1 -0
- package/dist/ModelLayer.test.d.ts +2 -0
- package/dist/ModelLayer.test.d.ts.map +1 -0
- package/dist/ModelLayer.test.js +83 -0
- package/dist/ModelLayer.test.js.map +1 -0
- package/dist/ModelsRepo.d.ts +80 -0
- package/dist/ModelsRepo.d.ts.map +1 -0
- package/dist/ModelsRepo.js +162 -0
- package/dist/ModelsRepo.js.map +1 -0
- package/dist/ModelsRepo.test.d.ts +2 -0
- package/dist/ModelsRepo.test.d.ts.map +1 -0
- package/dist/ModelsRepo.test.js +168 -0
- package/dist/ModelsRepo.test.js.map +1 -0
- package/dist/Xai.d.ts +12 -2
- package/dist/Xai.d.ts.map +1 -1
- package/dist/Xai.js +8 -2
- package/dist/Xai.js.map +1 -1
- package/dist/Xai.test.js +38 -7
- package/dist/Xai.test.js.map +1 -1
- package/dist/bin/{Effect-DuThyCJ1.mjs → Effect-4B1lzxy4.mjs} +2 -2
- package/dist/bin/{Effect-DuThyCJ1.mjs.map → Effect-4B1lzxy4.mjs.map} +1 -1
- package/dist/bin/{McpClient-CIiPyMDJ.mjs → McpClient-DMfHHEx3.mjs} +3 -3
- package/dist/bin/{McpClient-CIiPyMDJ.mjs.map → McpClient-DMfHHEx3.mjs.map} +1 -1
- package/dist/bin/{OutputFormatter-BvIjvUmT.mjs → OutputFormatter-DRycCEdr.mjs} +3 -3
- package/dist/bin/{OutputFormatter-BvIjvUmT.mjs.map → OutputFormatter-DRycCEdr.mjs.map} +1 -1
- package/dist/bin/{Schema-DcXUXpRg.mjs → Schema-D4fxUgEU.mjs} +3 -3
- package/dist/bin/{Schema-DcXUXpRg.mjs.map → Schema-D4fxUgEU.mjs.map} +1 -1
- package/dist/bin/{SemanticSearch-CdGA4CIC.mjs → SemanticSearch-BcLFv9qz.mjs} +4 -4
- package/dist/bin/{SemanticSearch-CdGA4CIC.mjs.map → SemanticSearch-BcLFv9qz.mjs.map} +1 -1
- package/dist/bin/{Stream-I9SRMlLj.mjs → Stream-i37nF1ep.mjs} +2 -2
- package/dist/bin/{Stream-I9SRMlLj.mjs.map → Stream-i37nF1ep.mjs.map} +1 -1
- package/dist/bin/cli.mjs +757 -420
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/cli.js +59 -46
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +32 -1
- package/src/Acp.ts +32 -12
- package/src/Codex.test.ts +60 -0
- package/src/Codex.ts +26 -14
- package/src/Copilot.test.ts +55 -0
- package/src/Copilot.ts +7 -4
- package/src/ModelLayer.test.ts +122 -0
- package/src/ModelLayer.ts +149 -0
- package/src/ModelsRepo.test.ts +206 -0
- package/src/ModelsRepo.ts +260 -0
- package/src/Xai.test.ts +62 -7
- package/src/Xai.ts +27 -8
- package/src/cli.ts +74 -81
- package/src/index.ts +5 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { assert, describe, it } from "@effect/vitest"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
|
+
import * as Layer from "effect/Layer"
|
|
4
|
+
import * as Option from "effect/Option"
|
|
5
|
+
import * as Redacted from "effect/Redacted"
|
|
6
|
+
import * as Stream from "effect/Stream"
|
|
7
|
+
import * as LanguageModel from "effect/ai/LanguageModel"
|
|
8
|
+
import * as HttpClient from "effect/http/HttpClient"
|
|
9
|
+
import type * as HttpClientRequest from "effect/http/HttpClientRequest"
|
|
10
|
+
import * as HttpClientResponse from "effect/http/HttpClientResponse"
|
|
11
|
+
import * as KeyValueStore from "effect/persistence/KeyValueStore"
|
|
12
|
+
import * as Socket from "effect/socket/Socket"
|
|
13
|
+
import type * as Acp from "./Acp.ts"
|
|
14
|
+
import { DeviceCodeHandler } from "./DeviceCodeHandler.ts"
|
|
15
|
+
import * as ModelLayer from "./ModelLayer.ts"
|
|
16
|
+
import * as ModelsRepo from "./ModelsRepo.ts"
|
|
17
|
+
|
|
18
|
+
const makeModel = ModelLayer.makeAcp({
|
|
19
|
+
models: Effect.succeed([
|
|
20
|
+
new ModelsRepo.ModelInfo({
|
|
21
|
+
provider: "openai",
|
|
22
|
+
id: "gpt-4.1",
|
|
23
|
+
name: "GPT-4.1",
|
|
24
|
+
efforts: [],
|
|
25
|
+
}),
|
|
26
|
+
new ModelsRepo.ModelInfo({
|
|
27
|
+
provider: "openai",
|
|
28
|
+
id: "gpt-6-astra",
|
|
29
|
+
name: "GPT-6 Astra",
|
|
30
|
+
efforts: ["low", "high"],
|
|
31
|
+
}),
|
|
32
|
+
new ModelsRepo.ModelInfo({
|
|
33
|
+
provider: "openai",
|
|
34
|
+
id: "gpt-5-pro",
|
|
35
|
+
name: "GPT-5 Pro",
|
|
36
|
+
efforts: ["high"],
|
|
37
|
+
}),
|
|
38
|
+
]),
|
|
39
|
+
openai: {
|
|
40
|
+
apiKey: Redacted.make("test-key"),
|
|
41
|
+
apiUrl: "https://codex.test",
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// The other providers' login and socket services, which the API-key openai
|
|
46
|
+
// path must not use.
|
|
47
|
+
const unused = Layer.mergeAll(
|
|
48
|
+
KeyValueStore.layerMemory,
|
|
49
|
+
Layer.succeed(DeviceCodeHandler, {
|
|
50
|
+
onCode: () => Effect.die("The API-key path must not log in"),
|
|
51
|
+
}),
|
|
52
|
+
Layer.succeed(Socket.WebSocketConstructor, () => {
|
|
53
|
+
throw new Error("Unexpected live WebSocket")
|
|
54
|
+
}),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
// The request body the model for `modelId` sends at session thought level
|
|
58
|
+
// `thoughtLevel`.
|
|
59
|
+
const requestBody = Effect.fnUntraced(function* (
|
|
60
|
+
modelId: string,
|
|
61
|
+
thoughtLevel: Acp.ThoughtLevel = "high",
|
|
62
|
+
) {
|
|
63
|
+
const requests: Array<HttpClientRequest.HttpClientRequest> = []
|
|
64
|
+
const client = HttpClient.make((request) =>
|
|
65
|
+
Effect.sync(() => {
|
|
66
|
+
requests.push(request)
|
|
67
|
+
return HttpClientResponse.fromWeb(
|
|
68
|
+
request,
|
|
69
|
+
new Response(null, { status: 400 }),
|
|
70
|
+
)
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
const model = Option.getOrThrow(makeModel(modelId, thoughtLevel))
|
|
74
|
+
yield* Effect.gen(function* () {
|
|
75
|
+
const ai = yield* LanguageModel.LanguageModel
|
|
76
|
+
yield* ai.streamText({ prompt: "hello" }).pipe(Stream.runDrain, Effect.exit)
|
|
77
|
+
}).pipe(
|
|
78
|
+
Effect.provide(
|
|
79
|
+
model.pipe(
|
|
80
|
+
Layer.provide([Layer.succeed(HttpClient.HttpClient, client), unused]),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
assert.lengthOf(requests, 1)
|
|
85
|
+
const body = requests[0]!.body
|
|
86
|
+
if (body._tag !== "Uint8Array") throw new Error("Expected JSON body")
|
|
87
|
+
return JSON.parse(new TextDecoder().decode(body.body)) as Record<string, any>
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe("ModelLayer.makeAcp", () => {
|
|
91
|
+
it.effect("sends no reasoning for a catalog model without efforts", () =>
|
|
92
|
+
Effect.gen(function* () {
|
|
93
|
+
assert.isFalse("reasoning" in (yield* requestBody("openai:gpt-4.1")))
|
|
94
|
+
}),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
for (const modelId of ["openai:gpt-6-astra", "openai:gpt-unlisted"]) {
|
|
98
|
+
it.effect("sends the session effort for " + modelId, () =>
|
|
99
|
+
Effect.gen(function* () {
|
|
100
|
+
assert.strictEqual(
|
|
101
|
+
(yield* requestBody(modelId)).reasoning?.effort,
|
|
102
|
+
"high",
|
|
103
|
+
)
|
|
104
|
+
}),
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
it.effect(
|
|
109
|
+
"sends a supported effort when the catalog model lacks the session effort",
|
|
110
|
+
() =>
|
|
111
|
+
Effect.gen(function* () {
|
|
112
|
+
assert.strictEqual(
|
|
113
|
+
(yield* requestBody("openai:gpt-5-pro", "medium")).reasoning?.effort,
|
|
114
|
+
"high",
|
|
115
|
+
)
|
|
116
|
+
}),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
it("rejects ids that are not <provider>:<model>", () => {
|
|
120
|
+
assert.isTrue(Option.isNone(makeModel("nope", "high")))
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the model layers the `clanka` CLI runs, for the interactive prompt
|
|
3
|
+
* and for `clanka acp`.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAiClient } from "@effect/ai-openai"
|
|
8
|
+
import type * as LanguageModel from "effect/ai/LanguageModel"
|
|
9
|
+
import type * as Model from "effect/ai/Model"
|
|
10
|
+
import * as Effect from "effect/Effect"
|
|
11
|
+
import * as Layer from "effect/Layer"
|
|
12
|
+
import * as Option from "effect/Option"
|
|
13
|
+
import * as Schema from "effect/Schema"
|
|
14
|
+
import { ThoughtLevel } from "./Acp.ts"
|
|
15
|
+
import * as Agent from "./Agent.ts"
|
|
16
|
+
import * as Codex from "./Codex.ts"
|
|
17
|
+
import * as Copilot from "./Copilot.ts"
|
|
18
|
+
import * as ModelsRepo from "./ModelsRepo.ts"
|
|
19
|
+
import * as Xai from "./Xai.ts"
|
|
20
|
+
|
|
21
|
+
const withSubagentModel = <E, R>(
|
|
22
|
+
model: Layer.Layer<
|
|
23
|
+
LanguageModel.LanguageModel | Model.ProviderName | Model.ModelName,
|
|
24
|
+
E,
|
|
25
|
+
R
|
|
26
|
+
>,
|
|
27
|
+
) => Layer.merge(model, Agent.layerSubagentModel(model))
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The model layer for a provider and model id. `effort` is `null` for models
|
|
31
|
+
* that take no reasoning effort, and `undefined` to keep the provider's
|
|
32
|
+
* default effort.
|
|
33
|
+
*
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
* @category Layers
|
|
36
|
+
*/
|
|
37
|
+
export const make = (
|
|
38
|
+
provider: ModelsRepo.Provider,
|
|
39
|
+
model: string,
|
|
40
|
+
effort: string | null | undefined,
|
|
41
|
+
openai: OpenAiClient.Options,
|
|
42
|
+
) => {
|
|
43
|
+
const options =
|
|
44
|
+
effort === undefined
|
|
45
|
+
? undefined
|
|
46
|
+
: { reasoning: effort === null ? null : { effort: effort as any } }
|
|
47
|
+
return provider === "openai"
|
|
48
|
+
? openai.apiKey !== undefined
|
|
49
|
+
? withSubagentModel(Codex.model(model, options)).pipe(
|
|
50
|
+
Layer.provide(OpenAiClient.layer(openai)),
|
|
51
|
+
)
|
|
52
|
+
: withSubagentModel(Codex.modelWebSocket(model, options)).pipe(
|
|
53
|
+
Layer.provide(Codex.layerClient),
|
|
54
|
+
)
|
|
55
|
+
: provider === "xai"
|
|
56
|
+
? withSubagentModel(Xai.modelWebSocket(model, options)).pipe(
|
|
57
|
+
Layer.provide(Xai.layerClient),
|
|
58
|
+
)
|
|
59
|
+
: withSubagentModel(Copilot.model(model, options)).pipe(
|
|
60
|
+
Layer.provide(Copilot.layerClient),
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const isProvider = Schema.is(ModelsRepo.Provider)
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Parses a `<provider>:<model>` id as advertised over ACP.
|
|
68
|
+
*
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
* @category Parsing
|
|
71
|
+
*/
|
|
72
|
+
export const parseAcpModelId = (modelId: string) => {
|
|
73
|
+
const [provider, model, ...rest] = modelId.split(":")
|
|
74
|
+
return isProvider(provider) && model !== undefined && rest.length === 0
|
|
75
|
+
? Option.some({ provider, model })
|
|
76
|
+
: Option.none()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The catalog as ACP `availableModels`, with `<provider>:<id>` ids. The
|
|
81
|
+
* provider is part of the name because providers share model names.
|
|
82
|
+
*
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
* @category ACP
|
|
85
|
+
*/
|
|
86
|
+
export const acpModels = (models: ReadonlyArray<ModelsRepo.ModelInfo>) =>
|
|
87
|
+
models.map((model) => ({
|
|
88
|
+
modelId: `${model.provider}:${model.id}`,
|
|
89
|
+
name: `${model.name} (${model.provider})`,
|
|
90
|
+
}))
|
|
91
|
+
|
|
92
|
+
const rank = (level: ThoughtLevel) => ThoughtLevel.literals.indexOf(level)
|
|
93
|
+
|
|
94
|
+
// The effort a catalog model with `efforts` runs at for a session
|
|
95
|
+
// `thoughtLevel`: `null` for no efforts, else the nearest supported effort,
|
|
96
|
+
// breaking ties upward.
|
|
97
|
+
const resolveEffort = (
|
|
98
|
+
efforts: ReadonlyArray<ThoughtLevel>,
|
|
99
|
+
thoughtLevel: ThoughtLevel,
|
|
100
|
+
): ThoughtLevel | null => {
|
|
101
|
+
const distance = (level: ThoughtLevel) =>
|
|
102
|
+
Math.abs(rank(level) - rank(thoughtLevel))
|
|
103
|
+
let resolved: ThoughtLevel | null = null
|
|
104
|
+
for (const effort of efforts) {
|
|
105
|
+
if (
|
|
106
|
+
resolved === null ||
|
|
107
|
+
distance(effort) < distance(resolved) ||
|
|
108
|
+
(distance(effort) === distance(resolved) && rank(effort) > rank(resolved))
|
|
109
|
+
) {
|
|
110
|
+
resolved = effort
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return resolved
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* An `Acp.Options.makeModel` callback. Ids that do not parse as
|
|
118
|
+
* `<provider>:<model>` are unknown models. A model the catalog lists without
|
|
119
|
+
* efforts runs with no reasoning options, whatever the session thought level.
|
|
120
|
+
* A listed model that does not support the session thought level runs at the
|
|
121
|
+
* supported effort nearest to it in `ThoughtLevel` order, the higher one on a
|
|
122
|
+
* tie. Unlisted models run at the session thought level.
|
|
123
|
+
*
|
|
124
|
+
* @since 1.0.0
|
|
125
|
+
* @category ACP
|
|
126
|
+
*/
|
|
127
|
+
export const makeAcp =
|
|
128
|
+
(options: {
|
|
129
|
+
readonly models: Effect.Effect<ReadonlyArray<ModelsRepo.ModelInfo>>
|
|
130
|
+
readonly openai: OpenAiClient.Options
|
|
131
|
+
}) =>
|
|
132
|
+
(modelId: string, thoughtLevel: ThoughtLevel) =>
|
|
133
|
+
Option.map(parseAcpModelId(modelId), ({ provider, model }) =>
|
|
134
|
+
Layer.unwrap(
|
|
135
|
+
Effect.map(options.models, (catalog) => {
|
|
136
|
+
const info = catalog.find(
|
|
137
|
+
(entry) => entry.provider === provider && entry.id === model,
|
|
138
|
+
)
|
|
139
|
+
return make(
|
|
140
|
+
provider,
|
|
141
|
+
model,
|
|
142
|
+
info === undefined
|
|
143
|
+
? thoughtLevel
|
|
144
|
+
: resolveEffort(info.efforts, thoughtLevel),
|
|
145
|
+
options.openai,
|
|
146
|
+
)
|
|
147
|
+
}),
|
|
148
|
+
),
|
|
149
|
+
)
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { assert, describe, it } from "@effect/vitest"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
|
+
import * as Layer from "effect/Layer"
|
|
4
|
+
import * as HttpClient from "effect/http/HttpClient"
|
|
5
|
+
import * as HttpClientError from "effect/http/HttpClientError"
|
|
6
|
+
import * as HttpClientResponse from "effect/http/HttpClientResponse"
|
|
7
|
+
import * as KeyValueStore from "effect/persistence/KeyValueStore"
|
|
8
|
+
import * as TestClock from "effect/testing/TestClock"
|
|
9
|
+
import * as ModelsRepo from "./ModelsRepo.ts"
|
|
10
|
+
|
|
11
|
+
// A trimmed `https://models.dev/api.json`: one provider clanka does not
|
|
12
|
+
// offer, and per provider the entries the catalog must keep and drop.
|
|
13
|
+
const apiJson = {
|
|
14
|
+
openai: {
|
|
15
|
+
id: "openai",
|
|
16
|
+
name: "OpenAI",
|
|
17
|
+
models: {
|
|
18
|
+
"gpt-6-astra": {
|
|
19
|
+
id: "gpt-6-astra",
|
|
20
|
+
name: "GPT-6 Astra",
|
|
21
|
+
tool_call: true,
|
|
22
|
+
reasoning: true,
|
|
23
|
+
reasoning_options: [
|
|
24
|
+
{
|
|
25
|
+
type: "effort",
|
|
26
|
+
values: ["low", "medium", "high", "xhigh", "max"],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
"gpt-4": {
|
|
31
|
+
id: "gpt-4",
|
|
32
|
+
name: "GPT-4",
|
|
33
|
+
tool_call: true,
|
|
34
|
+
reasoning: false,
|
|
35
|
+
status: "deprecated",
|
|
36
|
+
},
|
|
37
|
+
"gpt-image-2": {
|
|
38
|
+
id: "gpt-image-2",
|
|
39
|
+
name: "GPT Image 2",
|
|
40
|
+
type: "image",
|
|
41
|
+
tool_call: false,
|
|
42
|
+
reasoning: false,
|
|
43
|
+
},
|
|
44
|
+
"text-embedding-3-small": {
|
|
45
|
+
id: "text-embedding-3-small",
|
|
46
|
+
name: "text-embedding-3-small",
|
|
47
|
+
type: "embedding",
|
|
48
|
+
tool_call: false,
|
|
49
|
+
reasoning: false,
|
|
50
|
+
},
|
|
51
|
+
"gpt-chat-only": {
|
|
52
|
+
id: "gpt-chat-only",
|
|
53
|
+
name: "GPT Chat Only",
|
|
54
|
+
tool_call: false,
|
|
55
|
+
reasoning: false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
"github-copilot": {
|
|
60
|
+
id: "github-copilot",
|
|
61
|
+
name: "GitHub Copilot",
|
|
62
|
+
models: {
|
|
63
|
+
"claude-fable-5.1": {
|
|
64
|
+
id: "claude-fable-5.1",
|
|
65
|
+
name: "Claude Fable 5.1",
|
|
66
|
+
tool_call: true,
|
|
67
|
+
reasoning: true,
|
|
68
|
+
reasoning_options: [
|
|
69
|
+
{ type: "effort", values: ["low", "turbo", "high"] },
|
|
70
|
+
{ type: "budget_tokens", min: 1024, max: 32000 },
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
xai: {
|
|
76
|
+
id: "xai",
|
|
77
|
+
name: "xAI",
|
|
78
|
+
models: {
|
|
79
|
+
"grok-4.6": {
|
|
80
|
+
id: "grok-4.6",
|
|
81
|
+
name: "Grok 4.6",
|
|
82
|
+
tool_call: true,
|
|
83
|
+
reasoning: true,
|
|
84
|
+
reasoning_options: [
|
|
85
|
+
{ type: "effort", values: ["low", "medium", "high", "xhigh"] },
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
"grok-build-0.1": {
|
|
89
|
+
id: "grok-build-0.1",
|
|
90
|
+
name: "Grok Build 0.1",
|
|
91
|
+
tool_call: true,
|
|
92
|
+
reasoning: true,
|
|
93
|
+
reasoning_options: [],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
anthropic: {
|
|
98
|
+
id: "anthropic",
|
|
99
|
+
name: "Anthropic",
|
|
100
|
+
models: {
|
|
101
|
+
"claude-opus-5.5": {
|
|
102
|
+
id: "claude-opus-5.5",
|
|
103
|
+
name: "Claude Opus 5.5",
|
|
104
|
+
tool_call: true,
|
|
105
|
+
reasoning: true,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
|
|
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
|
+
new ModelsRepo.ModelInfo({
|
|
119
|
+
provider: "copilot",
|
|
120
|
+
id: "claude-fable-5.1",
|
|
121
|
+
name: "Claude Fable 5.1",
|
|
122
|
+
efforts: ["low", "high"],
|
|
123
|
+
}),
|
|
124
|
+
new ModelsRepo.ModelInfo({
|
|
125
|
+
provider: "xai",
|
|
126
|
+
id: "grok-4.6",
|
|
127
|
+
name: "Grok 4.6",
|
|
128
|
+
efforts: ["low", "medium", "high", "xhigh"],
|
|
129
|
+
}),
|
|
130
|
+
new ModelsRepo.ModelInfo({
|
|
131
|
+
provider: "xai",
|
|
132
|
+
id: "grok-build-0.1",
|
|
133
|
+
name: "Grok Build 0.1",
|
|
134
|
+
efforts: [],
|
|
135
|
+
}),
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
const online = HttpClient.make((request) =>
|
|
139
|
+
Effect.succeed(
|
|
140
|
+
HttpClientResponse.fromWeb(
|
|
141
|
+
request,
|
|
142
|
+
new Response(JSON.stringify(apiJson), {
|
|
143
|
+
headers: { "content-type": "application/json" },
|
|
144
|
+
}),
|
|
145
|
+
),
|
|
146
|
+
),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
// Fails every request and counts the attempts.
|
|
150
|
+
const offline = () => {
|
|
151
|
+
let requests = 0
|
|
152
|
+
const client = HttpClient.make((request) =>
|
|
153
|
+
Effect.suspend(() => {
|
|
154
|
+
requests++
|
|
155
|
+
return Effect.fail(
|
|
156
|
+
new HttpClientError.HttpClientError({
|
|
157
|
+
reason: new HttpClientError.TransportError({
|
|
158
|
+
request,
|
|
159
|
+
cause: new Error("getaddrinfo ENOTFOUND models.dev"),
|
|
160
|
+
}),
|
|
161
|
+
}),
|
|
162
|
+
)
|
|
163
|
+
}),
|
|
164
|
+
)
|
|
165
|
+
return { client, requests: () => requests }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const modelsWith = (client: HttpClient.HttpClient) =>
|
|
169
|
+
Effect.flatMap(ModelsRepo.ModelsRepo, (repo) => repo.models).pipe(
|
|
170
|
+
Effect.provide(
|
|
171
|
+
ModelsRepo.ModelsRepo.layerModelsDev().pipe(
|
|
172
|
+
Layer.provide(Layer.succeed(HttpClient.HttpClient, client)),
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
describe("ModelsRepo.layerModelsDev", () => {
|
|
178
|
+
it.effect(
|
|
179
|
+
"lists the openai, copilot and xai text models that accept tool calls",
|
|
180
|
+
() =>
|
|
181
|
+
Effect.gen(function* () {
|
|
182
|
+
assert.deepStrictEqual(yield* modelsWith(online), catalog)
|
|
183
|
+
}).pipe(Effect.provide(KeyValueStore.layerMemory)),
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
it.effect("serves an expired cached catalog when the refresh fails", () =>
|
|
187
|
+
Effect.gen(function* () {
|
|
188
|
+
yield* modelsWith(online)
|
|
189
|
+
yield* TestClock.adjust("25 hours")
|
|
190
|
+
const http = offline()
|
|
191
|
+
assert.deepStrictEqual(yield* modelsWith(http.client), catalog)
|
|
192
|
+
assert.strictEqual(http.requests(), 1)
|
|
193
|
+
}).pipe(Effect.provide(KeyValueStore.layerMemory)),
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
it.effect(
|
|
197
|
+
"serves the built-in catalog when models.dev is unreachable and nothing is cached",
|
|
198
|
+
() =>
|
|
199
|
+
Effect.gen(function* () {
|
|
200
|
+
assert.deepStrictEqual(
|
|
201
|
+
yield* modelsWith(offline().client),
|
|
202
|
+
ModelsRepo.fallback,
|
|
203
|
+
)
|
|
204
|
+
}).pipe(Effect.provide(KeyValueStore.layerMemory)),
|
|
205
|
+
)
|
|
206
|
+
})
|