clanka 0.13.2 → 0.15.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/src/Acp.ts CHANGED
@@ -63,6 +63,15 @@ export interface Options<RAgent, RModel> {
63
63
  * Thought level used for new sessions.
64
64
  */
65
65
  readonly defaultThoughtLevel: ThoughtLevel
66
+ /**
67
+ * Whether new sessions start in fast mode. Defaults to `false`.
68
+ */
69
+ readonly defaultFastMode?: boolean | undefined
70
+ /**
71
+ * Whether a model id supports fast mode. The `fast_mode` config option is
72
+ * offered only while the session model does. Defaults to no model.
73
+ */
74
+ readonly supportsFastMode?: ((modelId: string) => boolean) | undefined
66
75
  /**
67
76
  * Write one JSON-RPC message to the client.
68
77
  */
@@ -74,12 +83,14 @@ export interface Options<RAgent, RModel> {
74
83
  cwd: string,
75
84
  ) => Effect.Effect<Agent.Agent, never, Scope.Scope | RAgent>
76
85
  /**
77
- * Resolve a model id and thought level to the services an Agent needs.
86
+ * Resolve a model id, thought level and fast mode to the services an Agent
87
+ * needs. `fastMode` is only `true` for models `supportsFastMode` accepts.
78
88
  * `None` rejects the combination.
79
89
  */
80
90
  readonly makeModel: (
81
91
  modelId: string,
82
92
  thoughtLevel: ThoughtLevel,
93
+ fastMode: boolean,
83
94
  ) => Option.Option<Layer.Layer<ModelServices, never, RModel>>
84
95
  /**
85
96
  * Models to advertise as `availableModels`, listed first in this order. The
@@ -138,6 +149,11 @@ export class SessionRecord extends Schema.Class<SessionRecord>(
138
149
  cwd: Schema.String,
139
150
  model: Schema.String,
140
151
  thoughtLevel: ThoughtLevel,
152
+ /**
153
+ * The session's fast mode setting. It is kept across model switches and
154
+ * applies while the session model supports fast mode.
155
+ */
156
+ fastMode: Schema.optionalKey(Schema.Boolean),
141
157
  history: Prompt.Prompt,
142
158
  /**
143
159
  * The agent's executor environment, such as its working directory.
@@ -257,17 +273,33 @@ const SessionIdParams = Schema.Struct({
257
273
  sessionId: Schema.String,
258
274
  })
259
275
 
260
- const SetModelParams = Schema.Struct({
276
+ const SteerParams = Schema.Struct({
261
277
  sessionId: Schema.String,
262
- modelId: Schema.String,
278
+ message: Schema.String,
263
279
  })
264
280
 
265
- const SetConfigOptionParams = Schema.Struct({
281
+ const SetModelParams = Schema.Struct({
266
282
  sessionId: Schema.String,
267
- configId: Schema.Literal("thought_level"),
268
- value: ThoughtLevel,
283
+ modelId: Schema.String,
269
284
  })
270
285
 
286
+ // The `fast_mode` select values. A select works with every client; a
287
+ // `boolean` option needs the client's `configOptions.boolean` capability.
288
+ const FastModeValue = Schema.Literals(["off", "on"])
289
+
290
+ const SetConfigOptionParams = Schema.Union([
291
+ Schema.Struct({
292
+ sessionId: Schema.String,
293
+ configId: Schema.Literal("thought_level"),
294
+ value: ThoughtLevel,
295
+ }),
296
+ Schema.Struct({
297
+ sessionId: Schema.String,
298
+ configId: Schema.Literal("fast_mode"),
299
+ value: FastModeValue,
300
+ }),
301
+ ])
302
+
271
303
  const TextBlock = Schema.Struct({
272
304
  type: Schema.Literal("text"),
273
305
  text: Schema.String,
@@ -389,8 +421,14 @@ interface Session {
389
421
  readonly cwd: string
390
422
  model: string
391
423
  thoughtLevel: ThoughtLevel
424
+ fastMode: boolean
392
425
  readonly agent: Agent.Agent
393
426
  running: Fiber.Fiber<void, unknown> | undefined
427
+ /**
428
+ * The `_session/steer` messages sent to the running prompt, each delivered
429
+ * to the Agent by its fiber. `undefined` while the session takes none.
430
+ */
431
+ steers: Array<Steer> | undefined
394
432
  toolCalls: number
395
433
  readonly announcedSubagents: Set<number>
396
434
  /** Owns the Agent and the session's MCP servers. */
@@ -399,6 +437,11 @@ interface Session {
399
437
  mcpFailures: string | undefined
400
438
  }
401
439
 
440
+ interface Steer {
441
+ readonly message: string
442
+ readonly fiber: Fiber.Fiber<void>
443
+ }
444
+
402
445
  /**
403
446
  * @since 1.0.0
404
447
  * @category Constructors
@@ -452,9 +495,20 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
452
495
  sessionNotFound(sessionId),
453
496
  )
454
497
 
455
- const requireModel = (modelId: string, thoughtLevel: ThoughtLevel) =>
498
+ const supportsFastMode = (modelId: string) =>
499
+ options.supportsFastMode?.(modelId) ?? false
500
+
501
+ const requireModel = (
502
+ modelId: string,
503
+ thoughtLevel: ThoughtLevel,
504
+ fastMode: boolean,
505
+ ) =>
456
506
  Effect.fromOption(
457
- options.makeModel(modelId, thoughtLevel),
507
+ options.makeModel(
508
+ modelId,
509
+ thoughtLevel,
510
+ fastMode && supportsFastMode(modelId),
511
+ ),
458
512
  () =>
459
513
  new RpcError({ code: -32602, message: `Unknown model: ${modelId}` }),
460
514
  )
@@ -468,6 +522,24 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
468
522
  currentValue: session.thoughtLevel,
469
523
  options: ThoughtLevel.literals.map((value) => ({ value, name: value })),
470
524
  },
525
+ ...(supportsFastMode(session.model)
526
+ ? [
527
+ {
528
+ id: "fast_mode",
529
+ name: "Fast mode",
530
+ description: "Faster responses at a higher cost",
531
+ category: "model_config",
532
+ type: "select",
533
+ currentValue: session.fastMode ? "on" : "off",
534
+ // "off" sends no service tier, so the account or project default
535
+ // applies, and that default can itself be fast.
536
+ options: [
537
+ { value: "off", name: "Default" },
538
+ { value: "on", name: "On" },
539
+ ],
540
+ },
541
+ ]
542
+ : []),
471
543
  ]
472
544
 
473
545
  const sessionState = Effect.fnUntraced(function* (session: Session) {
@@ -498,6 +570,7 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
498
570
  cwd: session.cwd,
499
571
  model: session.model,
500
572
  thoughtLevel: session.thoughtLevel,
573
+ fastMode: session.fastMode,
501
574
  history: session.agent.history.current,
502
575
  environment: session.agent.environment.current,
503
576
  }),
@@ -545,8 +618,10 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
545
618
  cwd: record.cwd,
546
619
  model: record.model,
547
620
  thoughtLevel: record.thoughtLevel,
621
+ fastMode: record.fastMode ?? false,
548
622
  agent,
549
623
  running: undefined,
624
+ steers: undefined,
550
625
  toolCalls: 0,
551
626
  announcedSubagents: new Set(),
552
627
  scope: sessionScope,
@@ -868,6 +943,59 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
868
943
  )
869
944
  })
870
945
 
946
+ // Take back the steer messages the Agent has not read, in the order they
947
+ // were sent. A message read while it is taken back stays read.
948
+ const withdrawSteers = Effect.fnUntraced(function* (session: Session) {
949
+ const unread = (session.steers ?? []).filter(
950
+ ({ fiber }) => fiber.pollUnsafe() === undefined,
951
+ )
952
+ session.steers = []
953
+ yield* Fiber.interruptAll(unread.map(({ fiber }) => fiber))
954
+ return unread
955
+ .filter(({ fiber }) => {
956
+ const exit = fiber.pollUnsafe()
957
+ return exit === undefined || !Exit.isSuccess(exit)
958
+ })
959
+ .map(({ message }) => message)
960
+ })
961
+
962
+ // A turn can end with steer messages unread, for example when the model
963
+ // calls taskComplete while they arrive. They were reported as queued, so
964
+ // they start another turn of the same prompt.
965
+ const runPrompt = Effect.fnUntraced(
966
+ function* (session: Session, prompt: Prompt.RawInput) {
967
+ yield* Effect.scoped(runTurn(session, prompt))
968
+ while (true) {
969
+ // No yield between this check and closing the session to steering,
970
+ // so no message can arrive in between.
971
+ if (
972
+ session.steers!.every(({ fiber }) => fiber.pollUnsafe() !== undefined)
973
+ ) {
974
+ session.steers = undefined
975
+ return
976
+ }
977
+ const messages = yield* withdrawSteers(session)
978
+ if (messages.length > 0) {
979
+ yield* Effect.scoped(
980
+ runTurn(
981
+ session,
982
+ messages.map((content) => ({ role: "user", content })),
983
+ ),
984
+ )
985
+ }
986
+ }
987
+ },
988
+ // A failed or cancelled prompt drops the messages it has not read.
989
+ (effect, session) =>
990
+ effect.pipe(
991
+ Effect.onExit(() => {
992
+ const steers = session.steers ?? []
993
+ session.steers = undefined
994
+ return Fiber.interruptAll(steers.map(({ fiber }) => fiber))
995
+ }),
996
+ ),
997
+ )
998
+
871
999
  const initialize = Effect.succeed({
872
1000
  protocolVersion: 1,
873
1001
  agentCapabilities: {
@@ -887,13 +1015,15 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
887
1015
  )
888
1016
  const modelId = model ?? options.defaultModel
889
1017
  const thoughtLevel = options.defaultThoughtLevel
890
- yield* requireModel(modelId, thoughtLevel)
1018
+ const fastMode = options.defaultFastMode ?? false
1019
+ yield* requireModel(modelId, thoughtLevel, fastMode)
891
1020
  const session = yield* openSession(
892
1021
  crypto.randomUUID(),
893
1022
  new SessionRecord({
894
1023
  cwd,
895
1024
  model: modelId,
896
1025
  thoughtLevel,
1026
+ fastMode,
897
1027
  history: Prompt.empty,
898
1028
  }),
899
1029
  mcpServers ?? [],
@@ -925,13 +1055,15 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
925
1055
  return yield* sessionNotFound(sessionId)
926
1056
  }
927
1057
  const modelId = model ?? record.value.model
928
- yield* requireModel(modelId, record.value.thoughtLevel)
1058
+ const fastMode = record.value.fastMode ?? false
1059
+ yield* requireModel(modelId, record.value.thoughtLevel, fastMode)
929
1060
  const session = yield* openSession(
930
1061
  sessionId,
931
1062
  new SessionRecord({
932
1063
  cwd: cwd ?? record.value.cwd,
933
1064
  model: modelId,
934
1065
  thoughtLevel: record.value.thoughtLevel,
1066
+ fastMode,
935
1067
  history: record.value.history,
936
1068
  // The stored environment belongs to the stored cwd.
937
1069
  ...(record.value.environment !== undefined &&
@@ -950,20 +1082,35 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
950
1082
  const setModel = Effect.fnUntraced(function* (params: unknown) {
951
1083
  const { sessionId, modelId } = yield* decodeParams(SetModelParams, params)
952
1084
  const session = yield* getSession(sessionId)
953
- yield* requireModel(modelId, session.thoughtLevel)
1085
+ yield* requireModel(modelId, session.thoughtLevel, session.fastMode)
954
1086
  session.model = modelId
955
1087
  yield* persist(session)
956
- return { configOptions: configOptions(session) }
1088
+ // The options depend on the model, and the `session/set_model` response
1089
+ // has no `configOptions` field in the ACP schema.
1090
+ const options = configOptions(session)
1091
+ yield* update(sessionId, {
1092
+ sessionUpdate: "config_option_update",
1093
+ configOptions: options,
1094
+ })
1095
+ return { configOptions: options }
957
1096
  })
958
1097
 
959
1098
  const setConfigOption = Effect.fnUntraced(function* (params: unknown) {
960
- const { sessionId, value } = yield* decodeParams(
961
- SetConfigOptionParams,
962
- params,
963
- )
964
- const session = yield* getSession(sessionId)
965
- yield* requireModel(session.model, value)
966
- session.thoughtLevel = value
1099
+ const option = yield* decodeParams(SetConfigOptionParams, params)
1100
+ const session = yield* getSession(option.sessionId)
1101
+ if (option.configId === "thought_level") {
1102
+ yield* requireModel(session.model, option.value, session.fastMode)
1103
+ session.thoughtLevel = option.value
1104
+ } else {
1105
+ const fastMode = option.value === "on"
1106
+ if (fastMode && !supportsFastMode(session.model)) {
1107
+ return yield* invalidParams(
1108
+ `Fast mode is not supported by model: ${session.model}`,
1109
+ )
1110
+ }
1111
+ yield* requireModel(session.model, session.thoughtLevel, fastMode)
1112
+ session.fastMode = fastMode
1113
+ }
967
1114
  yield* persist(session)
968
1115
  return { configOptions: configOptions(session) }
969
1116
  })
@@ -977,7 +1124,11 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
977
1124
  message: `Session ${sessionId} already has a prompt in progress`,
978
1125
  })
979
1126
  }
980
- const model = yield* requireModel(session.model, session.thoughtLevel)
1127
+ const model = yield* requireModel(
1128
+ session.model,
1129
+ session.thoughtLevel,
1130
+ session.fastMode,
1131
+ )
981
1132
  // Resolve images before the turn starts, so a bad block rejects the
982
1133
  // request without a model call.
983
1134
  const input = yield* promptFromBlocks(session.cwd, prompt)
@@ -988,9 +1139,9 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
988
1139
  })
989
1140
  session.mcpFailures = undefined
990
1141
  }
991
- session.running = yield* runTurn(session, input).pipe(
1142
+ session.steers = []
1143
+ session.running = yield* runPrompt(session, input).pipe(
992
1144
  Effect.provide(model),
993
- Effect.scoped,
994
1145
  Effect.forkChild,
995
1146
  )
996
1147
  const exit = yield* Effect.exit(Fiber.join(session.running))
@@ -1001,6 +1152,20 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
1001
1152
  return yield* toRpcError(exit.cause)
1002
1153
  })
1003
1154
 
1155
+ // Adds a message to the running prompt, like kiro-cli's `_session/steer`.
1156
+ // `queued: true` promises the running prompt reads it, so the reply cannot
1157
+ // wait for the Agent, which reads messages between model calls.
1158
+ const steer = Effect.fnUntraced(function* (params: unknown) {
1159
+ const { sessionId, message } = yield* decodeParams(SteerParams, params)
1160
+ const session = sessions.get(sessionId)
1161
+ if (session?.steers === undefined) return { queued: false }
1162
+ const fiber = yield* session.agent
1163
+ .steer(message)
1164
+ .pipe(Effect.forkIn(session.scope, { startImmediately: true }))
1165
+ session.steers.push({ message, fiber })
1166
+ return { queued: true }
1167
+ })
1168
+
1004
1169
  // Ends the session in this process: its prompt, Agent and MCP servers. It
1005
1170
  // can be loaded again from the store.
1006
1171
  const closeSession = Effect.fnUntraced(function* (params: unknown) {
@@ -1046,6 +1211,8 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
1046
1211
  return setModel(params)
1047
1212
  case "session/prompt":
1048
1213
  return prompt(params)
1214
+ case "_session/steer":
1215
+ return steer(params)
1049
1216
  default:
1050
1217
  return Effect.fail(
1051
1218
  new RpcError({
@@ -27,10 +27,11 @@ const writeSkill = Effect.fnUntraced(function* (
27
27
  root: string,
28
28
  dir: string,
29
29
  content: string,
30
+ configDir = ".agents",
30
31
  ) {
31
32
  const fs = yield* FileSystem.FileSystem
32
33
  const path = yield* Path.Path
33
- const skillDir = path.join(root, ".agents", "skills", dir)
34
+ const skillDir = path.join(root, configDir, "skills", dir)
34
35
  yield* fs.makeDirectory(skillDir, { recursive: true })
35
36
  yield* fs.writeFileString(path.join(skillDir, "SKILL.md"), content)
36
37
  return path.join(skillDir, "SKILL.md")
@@ -220,8 +221,10 @@ describe("AgentSkills", () => {
220
221
  assert.deepStrictEqual(reads, [
221
222
  path.join(roots.project, ".agents", "skills"),
222
223
  path.join(roots.project, ".agents", "skills", "proj"),
224
+ path.join(roots.project, ".kiro", "skills"),
223
225
  path.join(roots.home, ".agents", "skills"),
224
226
  path.join(roots.home, ".agents", "skills", "usr"),
227
+ path.join(roots.home, ".kiro", "skills"),
225
228
  ])
226
229
  }),
227
230
  ).pipe(Effect.provide(NodeServices.layer)),
@@ -575,6 +578,37 @@ describe("AgentSkills", () => {
575
578
  ).pipe(Effect.provide(NodeServices.layer)),
576
579
  )
577
580
 
581
+ it.effect("catalogs project and user skills from .kiro/skills", () =>
582
+ withRoots(
583
+ Effect.fnUntraced(function* (roots) {
584
+ const projectLocation = yield* writeSkill(
585
+ roots.project,
586
+ "deploy",
587
+ skillFile("deploy", "Deploy the service"),
588
+ ".kiro",
589
+ )
590
+ const userLocation = yield* writeSkill(
591
+ roots.home,
592
+ "notes",
593
+ skillFile("notes", "Take notes"),
594
+ ".kiro",
595
+ )
596
+ const skills = yield* discover(roots)
597
+ assert.deepStrictEqual(
598
+ skills.map(({ name, location, source }) => ({
599
+ name,
600
+ location,
601
+ source,
602
+ })),
603
+ [
604
+ { name: "deploy", location: projectLocation, source: "project" },
605
+ { name: "notes", location: userLocation, source: "user" },
606
+ ],
607
+ )
608
+ }),
609
+ ).pipe(Effect.provide(NodeServices.layer)),
610
+ )
611
+
578
612
  it.effect("project skill overrides a user skill with the same name", () =>
579
613
  withRoots(
580
614
  Effect.fnUntraced(function* (roots) {
@@ -36,9 +36,17 @@ export class Skill extends Schema.Class<Skill>("Skill")({
36
36
  source: SkillSource,
37
37
  }) {}
38
38
 
39
+ // The `skills` directories under a project or home directory, in priority
40
+ // order. `.kiro/skills` is where kiro launchers such as Multica write skills.
41
+ const skillsRoots = (path: Path.Path, directory: string) => [
42
+ path.resolve(directory, ".agents", "skills"),
43
+ path.resolve(directory, ".kiro", "skills"),
44
+ ]
45
+
39
46
  /**
40
- * Scan project and user `.agents/skills/<dir>/SKILL.md` files, plus
41
- * `<hermesHome>/skills/<dir>/SKILL.md` when explicitly configured.
47
+ * Scan project and user `.agents/skills/<dir>/SKILL.md` and
48
+ * `.kiro/skills/<dir>/SKILL.md` files, plus `<hermesHome>/skills/<dir>/SKILL.md`
49
+ * when explicitly configured.
42
50
  *
43
51
  * Project names override Hermes names, which override user names.
44
52
  * The first name wins within each scope; an empty Hermes home is ignored.
@@ -59,12 +67,10 @@ export const discover: (options: {
59
67
  const path = yield* Path.Path
60
68
 
61
69
  const roots: Array<{ readonly root: string; readonly source: SkillSource }> =
62
- [
63
- {
64
- root: path.resolve(options.directory, ".agents", "skills"),
65
- source: "project",
66
- },
67
- ]
70
+ skillsRoots(path, options.directory).map((root) => ({
71
+ root,
72
+ source: "project",
73
+ }))
68
74
  if (
69
75
  options.hermesHome &&
70
76
  Option.isSome(options.hermesHome) &&
@@ -76,10 +82,9 @@ export const discover: (options: {
76
82
  })
77
83
  }
78
84
  if (Option.isSome(options.homeDirectory)) {
79
- roots.push({
80
- root: path.resolve(options.homeDirectory.value, ".agents", "skills"),
81
- source: "user",
82
- })
85
+ for (const root of skillsRoots(path, options.homeDirectory.value)) {
86
+ roots.push({ root, source: "user" })
87
+ }
83
88
  }
84
89
 
85
90
  const byName = new Map<string, Skill>()
@@ -93,8 +98,9 @@ export const discover: (options: {
93
98
  })
94
99
 
95
100
  /**
96
- * Scan only `<directory>/.agents/skills/<dir>/SKILL.md`, as `discover` does
97
- * for the project.
101
+ * Scan only `<directory>/.agents/skills/<dir>/SKILL.md` and
102
+ * `<directory>/.kiro/skills/<dir>/SKILL.md`, as `discover` does for the
103
+ * project.
98
104
  *
99
105
  * @since 1.0.0
100
106
  * @category Discovery
@@ -107,7 +113,13 @@ export const discoverProject: (
107
113
  FileSystem.FileSystem | Path.Path
108
114
  > = Effect.fnUntraced(function* (directory) {
109
115
  const path = yield* Path.Path
110
- return yield* scan(path.resolve(directory, ".agents", "skills"), "project")
116
+ const byName = new Map<string, Skill>()
117
+ for (const root of skillsRoots(path, directory)) {
118
+ for (const skill of yield* scan(root, "project")) {
119
+ if (!byName.has(skill.name)) byName.set(skill.name, skill)
120
+ }
121
+ }
122
+ return Array.from(byName.values())
111
123
  })
112
124
 
113
125
  // The skills in one `skills` directory. The first name wins.
@@ -59,6 +59,7 @@ const unused = Layer.mergeAll(
59
59
  const requestBody = Effect.fnUntraced(function* (
60
60
  modelId: string,
61
61
  thoughtLevel: Acp.ThoughtLevel = "high",
62
+ fastMode = false,
62
63
  ) {
63
64
  const requests: Array<HttpClientRequest.HttpClientRequest> = []
64
65
  const client = HttpClient.make((request) =>
@@ -70,7 +71,7 @@ const requestBody = Effect.fnUntraced(function* (
70
71
  )
71
72
  }),
72
73
  )
73
- const model = Option.getOrThrow(makeModel(modelId, thoughtLevel))
74
+ const model = Option.getOrThrow(makeModel(modelId, thoughtLevel, fastMode))
74
75
  yield* Effect.gen(function* () {
75
76
  const ai = yield* LanguageModel.LanguageModel
76
77
  yield* ai.streamText({ prompt: "hello" }).pipe(Stream.runDrain, Effect.exit)
@@ -116,6 +117,18 @@ describe("ModelLayer.makeAcp", () => {
116
117
  }),
117
118
  )
118
119
 
120
+ it.effect("sends the priority service tier in fast mode only", () =>
121
+ Effect.gen(function* () {
122
+ assert.strictEqual(
123
+ (yield* requestBody("openai:gpt-6-astra", "high", true)).service_tier,
124
+ "priority",
125
+ )
126
+ assert.isFalse(
127
+ "service_tier" in (yield* requestBody("openai:gpt-6-astra")),
128
+ )
129
+ }),
130
+ )
131
+
119
132
  it("rejects ids that are not <provider>:<model>", () => {
120
133
  assert.isTrue(Option.isNone(makeModel("nope", "high")))
121
134
  })
package/src/ModelLayer.ts CHANGED
@@ -26,10 +26,21 @@ const withSubagentModel = <E, R>(
26
26
  >,
27
27
  ) => Layer.merge(model, Agent.layerSubagentModel(model))
28
28
 
29
+ /**
30
+ * Whether a provider supports fast mode. Only OpenAI does, through the
31
+ * `priority` service tier.
32
+ *
33
+ * @since 1.0.0
34
+ * @category Fast mode
35
+ */
36
+ export const supportsFastMode = (provider: ModelsRepo.Provider) =>
37
+ provider === "openai"
38
+
29
39
  /**
30
40
  * The model layer for a provider and model id. `effort` is `null` for models
31
41
  * that take no reasoning effort, and `undefined` to keep the provider's
32
- * default effort.
42
+ * default effort. `fastMode` requests the `priority` service tier and is
43
+ * ignored for providers without fast mode.
33
44
  *
34
45
  * @since 1.0.0
35
46
  * @category Layers
@@ -39,17 +50,21 @@ export const make = (
39
50
  model: string,
40
51
  effort: string | null | undefined,
41
52
  openai: OpenAiClient.Options,
53
+ fastMode = false,
42
54
  ) => {
43
55
  const options =
44
56
  effort === undefined
45
57
  ? undefined
46
58
  : { reasoning: effort === null ? null : { effort: effort as any } }
59
+ const openaiOptions = fastMode
60
+ ? { ...options, service_tier: "priority" }
61
+ : options
47
62
  return provider === "openai"
48
63
  ? openai.apiKey !== undefined
49
- ? withSubagentModel(Codex.model(model, options)).pipe(
64
+ ? withSubagentModel(Codex.model(model, openaiOptions)).pipe(
50
65
  Layer.provide(OpenAiClient.layer(openai)),
51
66
  )
52
- : withSubagentModel(Codex.modelWebSocket(model, options)).pipe(
67
+ : withSubagentModel(Codex.modelWebSocket(model, openaiOptions)).pipe(
53
68
  Layer.provide(Codex.layerClient),
54
69
  )
55
70
  : provider === "xai"
@@ -76,6 +91,17 @@ export const parseAcpModelId = (modelId: string) => {
76
91
  : Option.none()
77
92
  }
78
93
 
94
+ /**
95
+ * An `Acp.Options.supportsFastMode` callback for `<provider>:<model>` ids.
96
+ *
97
+ * @since 1.0.0
98
+ * @category ACP
99
+ */
100
+ export const acpSupportsFastMode = (modelId: string) =>
101
+ Option.exists(parseAcpModelId(modelId), ({ provider }) =>
102
+ supportsFastMode(provider),
103
+ )
104
+
79
105
  /**
80
106
  * The catalog as ACP `availableModels`, with `<provider>:<id>` ids. The
81
107
  * provider is part of the name because providers share model names.
@@ -119,7 +145,8 @@ const resolveEffort = (
119
145
  * efforts runs with no reasoning options, whatever the session thought level.
120
146
  * A listed model that does not support the session thought level runs at the
121
147
  * supported effort nearest to it in `ThoughtLevel` order, the higher one on a
122
- * tie. Unlisted models run at the session thought level.
148
+ * tie. Unlisted models run at the session thought level. Fast mode applies
149
+ * to OpenAI models only.
123
150
  *
124
151
  * @since 1.0.0
125
152
  * @category ACP
@@ -129,7 +156,7 @@ export const makeAcp =
129
156
  readonly models: Effect.Effect<ReadonlyArray<ModelsRepo.ModelInfo>>
130
157
  readonly openai: OpenAiClient.Options
131
158
  }) =>
132
- (modelId: string, thoughtLevel: ThoughtLevel) =>
159
+ (modelId: string, thoughtLevel: ThoughtLevel, fastMode = false) =>
133
160
  Option.map(parseAcpModelId(modelId), ({ provider, model }) =>
134
161
  Layer.unwrap(
135
162
  Effect.map(options.models, (catalog) => {
@@ -143,6 +170,7 @@ export const makeAcp =
143
170
  ? thoughtLevel
144
171
  : resolveEffort(info.efforts, thoughtLevel),
145
172
  options.openai,
173
+ fastMode,
146
174
  )
147
175
  }),
148
176
  ),