@leitwerk-dev/telegram 0.1.9 → 0.2.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 (71) hide show
  1. package/README.md +9 -1
  2. package/dist/actions.d.ts +1 -0
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actor.d.ts +1 -1
  5. package/dist/actor.d.ts.map +1 -1
  6. package/dist/bridge.d.ts +13 -10
  7. package/dist/bridge.d.ts.map +1 -1
  8. package/dist/config.d.ts +18 -0
  9. package/dist/config.d.ts.map +1 -1
  10. package/dist/fake-telegram-client.d.ts +60 -0
  11. package/dist/fake-telegram-client.d.ts.map +1 -1
  12. package/dist/form-session.d.ts +112 -19
  13. package/dist/form-session.d.ts.map +1 -1
  14. package/dist/grammy-telegram-client.d.ts +17 -41
  15. package/dist/grammy-telegram-client.d.ts.map +1 -1
  16. package/dist/index.d.ts +1 -16
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +3580 -52
  19. package/dist/index.js.map +1 -1
  20. package/dist/launch-session.d.ts +84 -1
  21. package/dist/launch-session.d.ts.map +1 -1
  22. package/dist/markdown-html.d.ts +19 -0
  23. package/dist/markdown-html.d.ts.map +1 -1
  24. package/dist/process-thread-store.d.ts +8 -0
  25. package/dist/process-thread-store.d.ts.map +1 -1
  26. package/dist/topic-title.d.ts +4 -0
  27. package/dist/topic-title.d.ts.map +1 -1
  28. package/dist/types.d.ts +99 -6
  29. package/dist/types.d.ts.map +1 -1
  30. package/package.json +7 -7
  31. package/src/actions.ts +14 -5
  32. package/src/actor.ts +1 -1
  33. package/src/bridge.ts +123 -303
  34. package/src/config.ts +37 -9
  35. package/src/fake-telegram-client.ts +92 -9
  36. package/src/form-session.ts +153 -42
  37. package/src/grammy-telegram-client.ts +23 -43
  38. package/src/index.ts +7 -12
  39. package/src/launch-session.ts +165 -70
  40. package/src/markdown-html.ts +35 -4
  41. package/src/process-thread-store.ts +8 -0
  42. package/src/topic-title.ts +8 -1
  43. package/src/types.ts +113 -10
  44. package/dist/actions.js +0 -32
  45. package/dist/actions.js.map +0 -1
  46. package/dist/actor.js +0 -7
  47. package/dist/actor.js.map +0 -1
  48. package/dist/bridge.js +0 -2032
  49. package/dist/bridge.js.map +0 -1
  50. package/dist/config.js +0 -70
  51. package/dist/config.js.map +0 -1
  52. package/dist/fake-telegram-client.js +0 -107
  53. package/dist/fake-telegram-client.js.map +0 -1
  54. package/dist/form-session.js +0 -218
  55. package/dist/form-session.js.map +0 -1
  56. package/dist/grammy-telegram-client.js +0 -195
  57. package/dist/grammy-telegram-client.js.map +0 -1
  58. package/dist/launch-session.js +0 -435
  59. package/dist/launch-session.js.map +0 -1
  60. package/dist/markdown-html.js +0 -259
  61. package/dist/markdown-html.js.map +0 -1
  62. package/dist/mermaid-image.js +0 -99
  63. package/dist/mermaid-image.js.map +0 -1
  64. package/dist/process-feed.js +0 -165
  65. package/dist/process-feed.js.map +0 -1
  66. package/dist/process-thread-store.js +0 -74
  67. package/dist/process-thread-store.js.map +0 -1
  68. package/dist/topic-title.js +0 -29
  69. package/dist/topic-title.js.map +0 -1
  70. package/dist/types.js +0 -19
  71. package/dist/types.js.map +0 -1
@@ -4,7 +4,7 @@ import {
4
4
  BaseTelegramClientEventRegistrar,
5
5
  type TelegramCallbackUpdate,
6
6
  type TelegramClient,
7
- type TelegramForumTopicClosedUpdate,
7
+ type TelegramForumTopicCreatedHandler,
8
8
  type TelegramForumTopicCreatedUpdate,
9
9
  type TelegramReplyMarkup,
10
10
  type TelegramSendFileInput,
@@ -44,11 +44,11 @@ interface GrammyBotLike {
44
44
  on(filter: "message:text", handler: (ctx: GrammyTextContext) => void | Promise<void>): void;
45
45
  on(
46
46
  filter: "message:forum_topic_created",
47
- handler: (ctx: GrammyForumTopicCreatedContext) => void | Promise<void>,
47
+ handler: (ctx: GrammyForumTopicContext) => void | Promise<void>,
48
48
  ): void;
49
49
  on(
50
50
  filter: "message:forum_topic_closed",
51
- handler: (ctx: GrammyForumTopicClosedContext) => void | Promise<void>,
51
+ handler: (ctx: GrammyForumTopicContext) => void | Promise<void>,
52
52
  ): void;
53
53
  on(
54
54
  filter: "callback_query:data",
@@ -58,34 +58,19 @@ interface GrammyBotLike {
58
58
  stop(): Promise<void>;
59
59
  }
60
60
 
61
- interface GrammyTextContext {
62
- message: {
63
- message_id: number;
64
- message_thread_id?: number;
65
- chat: { id: number | string };
66
- from?: { id: number; username?: string };
67
- text: string;
68
- };
61
+ interface GrammyMessage {
62
+ message_id: number;
63
+ message_thread_id?: number;
64
+ chat: { id: number | string };
65
+ from?: { id: number; username?: string };
69
66
  }
70
67
 
71
- interface GrammyForumTopicCreatedContext {
72
- message: {
73
- message_id: number;
74
- message_thread_id?: number;
75
- chat: { id: number | string };
76
- from?: { id: number; username?: string };
77
- forum_topic_created: unknown;
78
- };
68
+ interface GrammyTextContext {
69
+ message: GrammyMessage & { text: string };
79
70
  }
80
71
 
81
- interface GrammyForumTopicClosedContext {
82
- message: {
83
- message_id: number;
84
- message_thread_id?: number;
85
- chat: { id: number | string };
86
- from?: { id: number; username?: string };
87
- forum_topic_closed: unknown;
88
- };
72
+ interface GrammyForumTopicContext {
73
+ message: GrammyMessage;
89
74
  }
90
75
 
91
76
  interface GrammyCallbackContext {
@@ -144,8 +129,12 @@ export class GrammyTelegramClient
144
129
  this.bot =
145
130
  input.botFactory?.(input.botToken) ?? (new Bot(input.botToken) as unknown as GrammyBotLike);
146
131
  this.bot.on("message:text", (ctx) => this.dispatchText(ctx));
147
- this.bot.on("message:forum_topic_created", (ctx) => this.dispatchForumTopicCreated(ctx));
148
- this.bot.on("message:forum_topic_closed", (ctx) => this.dispatchForumTopicClosed(ctx));
132
+ this.bot.on("message:forum_topic_created", (ctx) =>
133
+ this.dispatchForumTopic(ctx, this.forumTopicCreatedHandlers),
134
+ );
135
+ this.bot.on("message:forum_topic_closed", (ctx) =>
136
+ this.dispatchForumTopic(ctx, this.forumTopicClosedHandlers),
137
+ );
149
138
  this.bot.on("callback_query:data", (ctx) => this.dispatchCallback(ctx));
150
139
  }
151
140
 
@@ -288,7 +277,10 @@ export class GrammyTelegramClient
288
277
  await Promise.all([...this.textHandlers].map((handler) => handler(update)));
289
278
  }
290
279
 
291
- private async dispatchForumTopicCreated(ctx: GrammyForumTopicCreatedContext): Promise<void> {
280
+ private async dispatchForumTopic(
281
+ ctx: GrammyForumTopicContext,
282
+ handlers: ReadonlySet<TelegramForumTopicCreatedHandler>,
283
+ ): Promise<void> {
292
284
  const message = ctx.message;
293
285
  if (message.message_thread_id === undefined) return;
294
286
  const update: TelegramForumTopicCreatedUpdate = {
@@ -297,19 +289,7 @@ export class GrammyTelegramClient
297
289
  messageThreadId: message.message_thread_id,
298
290
  from: toUserRef(message.from),
299
291
  };
300
- await Promise.all([...this.forumTopicCreatedHandlers].map((handler) => handler(update)));
301
- }
302
-
303
- private async dispatchForumTopicClosed(ctx: GrammyForumTopicClosedContext): Promise<void> {
304
- const message = ctx.message;
305
- if (message.message_thread_id === undefined) return;
306
- const update: TelegramForumTopicClosedUpdate = {
307
- messageId: message.message_id,
308
- chatId: String(message.chat.id),
309
- messageThreadId: message.message_thread_id,
310
- from: toUserRef(message.from),
311
- };
312
- await Promise.all([...this.forumTopicClosedHandlers].map((handler) => handler(update)));
292
+ await Promise.all([...handlers].map((handler) => handler(update)));
313
293
  }
314
294
 
315
295
  private async dispatchCallback(ctx: GrammyCallbackContext): Promise<void> {
package/src/index.ts CHANGED
@@ -8,13 +8,18 @@ import { normalizeTelegramConfig } from "./config.js";
8
8
  import { GrammyTelegramClient } from "./grammy-telegram-client.js";
9
9
  import type { TelegramClient } from "./types.js";
10
10
 
11
- export const telegramClientToken = createCapabilityToken<TelegramClient>("telegram:client");
11
+ /** @internal */
12
+ const telegramClientToken = createCapabilityToken<TelegramClient>("telegram:client");
12
13
 
13
- export const manifest = {
14
+ /** @internal */
15
+ const manifest = {
16
+ /** @internal */
14
17
  id: "telegram",
18
+ /** @internal */
15
19
  version: "0.1.0",
16
20
  } as const;
17
21
 
22
+ /** @public */
18
23
  const telegramExtension: LeitwerkExtensionModule = {
19
24
  manifest,
20
25
  setupServer(api, rawConfig) {
@@ -57,13 +62,3 @@ const telegramExtension: LeitwerkExtensionModule = {
57
62
  };
58
63
 
59
64
  export default telegramExtension;
60
- export { TELEGRAM_ACTOR } from "./actor.js";
61
- export * from "./bridge.js";
62
- export * from "./config.js";
63
- export * from "./fake-telegram-client.js";
64
- export * from "./form-session.js";
65
- export * from "./launch-session.js";
66
- export * from "./markdown-html.js";
67
- export * from "./process-thread-store.js";
68
- export * from "./topic-title.js";
69
- export type * from "./types.js";
@@ -14,52 +14,138 @@ import type {
14
14
  UiLauncherSummary,
15
15
  } from "@leitwerk-dev/process-sdk";
16
16
 
17
+ /** @internal */
17
18
  export type LaunchFieldValue = string | number | boolean;
18
19
 
20
+ /** @internal */
19
21
  export type LaunchModelStep =
20
- | { kind: "default"; key: "default"; label: string }
21
- | { kind: "turn"; key: string; turnId: string; label: string };
22
-
22
+ | {
23
+ /** @internal */
24
+ kind: "default";
25
+ /** @internal */
26
+ key: "default";
27
+ /** @internal */
28
+ label: string;
29
+ }
30
+ | {
31
+ /** @internal */
32
+ kind: "turn";
33
+ /** @internal */
34
+ key: string;
35
+ /** @internal */
36
+ turnId: string;
37
+ /** @internal */
38
+ label: string;
39
+ };
40
+
41
+ /** @internal */
23
42
  export interface PendingLaunchModelEdit {
43
+ /** @internal */
24
44
  stepIndex: number;
25
45
  }
26
46
 
47
+ /** @internal */
27
48
  export interface PendingLaunchSession {
49
+ /** @internal */
28
50
  kind: "launch";
51
+ /** @internal */
29
52
  launcherId: string;
53
+ /** @internal */
30
54
  fieldIndex: number;
55
+ /** @internal */
31
56
  fieldOrder: readonly string[];
57
+ /** @internal */
32
58
  values: Record<string, LaunchFieldValue>;
59
+ /** @internal */
33
60
  modelConfig: LaunchModelConfigInputLike;
61
+ /** @internal */
34
62
  modelConfigTouched: boolean;
63
+ /** @internal */
35
64
  modelEdit: PendingLaunchModelEdit | null;
65
+ /** @internal */
36
66
  expiresAt: number;
37
67
  }
38
68
 
69
+ /** @internal */
39
70
  export type LaunchFieldStepResult =
40
- | { ok: true; done: false; field: LauncherFieldDefinition }
41
- | { ok: true; done: true; values: Record<string, LaunchFieldValue> }
42
- | { ok: false; prompt: string };
43
-
71
+ | {
72
+ /** @internal */
73
+ ok: true;
74
+ /** @internal */
75
+ done: false;
76
+ /** @internal */
77
+ field: LauncherFieldDefinition;
78
+ }
79
+ | {
80
+ /** @internal */
81
+ ok: true;
82
+ /** @internal */
83
+ done: true;
84
+ /** @internal */
85
+ values: Record<string, LaunchFieldValue>;
86
+ }
87
+ | {
88
+ /** @internal */
89
+ ok: false;
90
+ /** @internal */
91
+ prompt: string;
92
+ };
93
+
94
+ /** @internal */
44
95
  export type LaunchModelStepResult =
45
- | { ok: true; done: false; step: LaunchModelStep }
46
- | { ok: true; done: true }
47
- | { ok: false; prompt: string };
48
-
96
+ | {
97
+ /** @internal */
98
+ ok: true;
99
+ /** @internal */
100
+ done: false;
101
+ /** @internal */
102
+ step: LaunchModelStep;
103
+ }
104
+ | {
105
+ /** @internal */
106
+ ok: true;
107
+ /** @internal */
108
+ done: true;
109
+ }
110
+ | {
111
+ /** @internal */
112
+ ok: false;
113
+ /** @internal */
114
+ prompt: string;
115
+ };
116
+
117
+ /** @internal */
49
118
  export type LaunchModelStepAction =
50
- | { action: "set"; value: string }
51
- | { action: "inherit" }
52
- | { action: "skip" };
53
-
119
+ | {
120
+ /** @internal */
121
+ action: "set";
122
+ /** @internal */
123
+ value: string;
124
+ }
125
+ | {
126
+ /** @internal */
127
+ action: "inherit";
128
+ }
129
+ | {
130
+ /** @internal */
131
+ action: "skip";
132
+ };
133
+
134
+ /** @internal */
54
135
  export type LaunchFieldOptionsById = Record<
55
136
  string,
56
137
  readonly LauncherFieldOptionDefinition[] | undefined
57
138
  >;
58
139
 
140
+ /** @internal */
59
141
  export function createLaunchSession(input: {
142
+ /** @internal */
60
143
  launcher: UiLauncherSummary;
144
+ /** @internal */
61
145
  defaults?: Record<string, unknown>;
146
+ /** @internal */
62
147
  now?: number;
148
+ /** @internal */
63
149
  ttlMs?: number;
64
150
  }): PendingLaunchSession {
65
151
  const values: Record<string, LaunchFieldValue> = {};
@@ -82,14 +168,17 @@ export function createLaunchSession(input: {
82
168
  };
83
169
  }
84
170
 
85
- export function buildLaunchInput(session: PendingLaunchSession): Record<string, unknown> {
171
+ /** @internal */
172
+ export function buildLaunchInput(session: PendingLaunchSession): PendingLaunchSession["values"] {
86
173
  return { ...session.values };
87
174
  }
88
175
 
176
+ /** @internal */
89
177
  export function buildLaunchModelConfig(session: PendingLaunchSession): LaunchModelConfigInputLike {
90
178
  return normalizeLaunchModelConfigInput(session.modelConfig);
91
179
  }
92
180
 
181
+ /** @internal */
93
182
  export function seedLaunchModelConfigFromPlan(
94
183
  session: PendingLaunchSession,
95
184
  launchPlan: ProcessLaunchPlan,
@@ -105,6 +194,7 @@ export function seedLaunchModelConfigFromPlan(
105
194
  });
106
195
  }
107
196
 
197
+ /** @internal */
108
198
  export function hasLaunchModelControls(
109
199
  schema: LauncherModelConfigSchemaLike | null | undefined,
110
200
  ): schema is LauncherModelConfigSchemaLike {
@@ -123,6 +213,7 @@ function buildLaunchModelStepOrder(schema: LauncherModelConfigSchemaLike): Launc
123
213
  ];
124
214
  }
125
215
 
216
+ /** @internal */
126
217
  export function beginLaunchModelEdit(
127
218
  session: PendingLaunchSession,
128
219
  schema: LauncherModelConfigSchemaLike,
@@ -131,6 +222,7 @@ export function beginLaunchModelEdit(
131
222
  return { ok: true, done: false, step: buildLaunchModelStepOrder(schema)[0] as LaunchModelStep };
132
223
  }
133
224
 
225
+ /** @internal */
134
226
  export function currentLaunchModelStep(
135
227
  session: PendingLaunchSession,
136
228
  schema: LauncherModelConfigSchemaLike,
@@ -139,10 +231,12 @@ export function currentLaunchModelStep(
139
231
  return buildLaunchModelStepOrder(schema)[session.modelEdit.stepIndex] ?? null;
140
232
  }
141
233
 
234
+ /** @internal */
142
235
  export function finishLaunchModelEdit(session: PendingLaunchSession): void {
143
236
  session.modelEdit = null;
144
237
  }
145
238
 
239
+ /** @internal */
146
240
  export function currentLaunchField(
147
241
  session: PendingLaunchSession,
148
242
  launcher: UiLauncherSummary,
@@ -153,10 +247,12 @@ export function currentLaunchField(
153
247
  : null;
154
248
  }
155
249
 
250
+ /** @internal */
156
251
  export function isLaunchSessionComplete(session: PendingLaunchSession): boolean {
157
252
  return session.fieldIndex >= session.fieldOrder.length;
158
253
  }
159
254
 
255
+ /** @internal */
160
256
  export function getLaunchFieldOptions(
161
257
  field: LauncherFieldDefinition,
162
258
  dynamicOptionsById: LaunchFieldOptionsById,
@@ -165,11 +261,17 @@ export function getLaunchFieldOptions(
165
261
  return dynamicOptionsById[field.id] ?? field.options ?? [];
166
262
  }
167
263
 
264
+ /** @internal */
168
265
  export function buildLaunchFieldPrompt(input: {
266
+ /** @internal */
169
267
  field: LauncherFieldDefinition;
268
+ /** @internal */
170
269
  currentValue?: LaunchFieldValue;
270
+ /** @internal */
171
271
  options?: readonly LauncherFieldOptionDefinition[];
272
+ /** @internal */
172
273
  recentValues?: readonly string[];
274
+ /** @internal */
173
275
  maxOptionsInPrompt?: number;
174
276
  }): string {
175
277
  const { field } = input;
@@ -208,9 +310,13 @@ export function buildLaunchFieldPrompt(input: {
208
310
  return lines.join("\n");
209
311
  }
210
312
 
313
+ /** @internal */
211
314
  export function buildLaunchModelSummary(input: {
315
+ /** @internal */
212
316
  schema: LauncherModelConfigSchemaLike;
317
+ /** @internal */
213
318
  session: PendingLaunchSession;
319
+ /** @internal */
214
320
  preview?: LauncherModelConfigPreviewLike | null;
215
321
  }): string {
216
322
  const config = buildLaunchModelConfig(input.session);
@@ -234,11 +340,17 @@ export function buildLaunchModelSummary(input: {
234
340
  return lines.join("\n");
235
341
  }
236
342
 
343
+ /** @internal */
237
344
  export function buildLaunchModelStepPrompt(input: {
345
+ /** @internal */
238
346
  step: LaunchModelStep;
347
+ /** @internal */
239
348
  schema: LauncherModelConfigSchemaLike;
349
+ /** @internal */
240
350
  session: PendingLaunchSession;
351
+ /** @internal */
241
352
  preview?: LauncherModelConfigPreviewLike | null;
353
+ /** @internal */
242
354
  maxOptionsInPrompt?: number;
243
355
  }): string {
244
356
  const currentOverride = getLaunchModelStepOverride(input.session, input.step);
@@ -262,6 +374,7 @@ export function buildLaunchModelStepPrompt(input: {
262
374
  return lines.join("\n");
263
375
  }
264
376
 
377
+ /** @internal */
265
378
  export function applyLaunchModelStepText(
266
379
  session: PendingLaunchSession,
267
380
  schema: LauncherModelConfigSchemaLike,
@@ -277,12 +390,17 @@ export function applyLaunchModelStepText(
277
390
  if (["inherit", "inherited", "clear", "none"].includes(normalized)) {
278
391
  return applyLaunchModelStepAction(session, schema, { action: "inherit" });
279
392
  }
280
- const matched = matchModelProfile(trimmed, schema);
393
+ const matched = matchByNumberValueOrLabel(
394
+ trimmed,
395
+ schema.availableProfiles,
396
+ (profile) => profile.id,
397
+ );
281
398
  return matched
282
399
  ? applyLaunchModelStepAction(session, schema, { action: "set", value: matched.id })
283
400
  : launchModelStepError(step, schema, session);
284
401
  }
285
402
 
403
+ /** @internal */
286
404
  export function applyLaunchModelStepAction(
287
405
  session: PendingLaunchSession,
288
406
  schema: LauncherModelConfigSchemaLike,
@@ -292,7 +410,7 @@ export function applyLaunchModelStepAction(
292
410
  if (!step) return { ok: true, done: true };
293
411
  if (action.action === "skip") return advanceLaunchModelStep(session, schema);
294
412
  if (action.action === "inherit") {
295
- clearLaunchModelStepOverride(session, step);
413
+ setLaunchModelStepOverride(session, step, null);
296
414
  return advanceLaunchModelStep(session, schema);
297
415
  }
298
416
  const matched = schema.availableProfiles.find((profile) => profile.id === action.value);
@@ -301,6 +419,18 @@ export function applyLaunchModelStepAction(
301
419
  return advanceLaunchModelStep(session, schema);
302
420
  }
303
421
 
422
+ function advanceLaunchField(
423
+ session: PendingLaunchSession,
424
+ launcher: UiLauncherSummary,
425
+ ): LaunchFieldStepResult {
426
+ session.fieldIndex += 1;
427
+ const field = currentLaunchField(session, launcher);
428
+ return field
429
+ ? { ok: true, done: false, field }
430
+ : { ok: true, done: true, values: buildLaunchInput(session) };
431
+ }
432
+
433
+ /** @internal */
304
434
  export function applyLaunchFieldText(
305
435
  session: PendingLaunchSession,
306
436
  launcher: UiLauncherSummary,
@@ -312,7 +442,7 @@ export function applyLaunchFieldText(
312
442
  return {
313
443
  ok: true,
314
444
  done: true,
315
- values: buildLaunchInput(session) as Record<string, LaunchFieldValue>,
445
+ values: buildLaunchInput(session),
316
446
  };
317
447
  }
318
448
  const options = getLaunchFieldOptions(field, dynamicOptionsById);
@@ -330,17 +460,10 @@ export function applyLaunchFieldText(
330
460
  if (parsed.setValue) {
331
461
  session.values[field.id] = parsed.value;
332
462
  }
333
- session.fieldIndex += 1;
334
- const next = currentLaunchField(session, launcher);
335
- return next
336
- ? { ok: true, done: false, field: next }
337
- : {
338
- ok: true,
339
- done: true,
340
- values: buildLaunchInput(session) as Record<string, LaunchFieldValue>,
341
- };
463
+ return advanceLaunchField(session, launcher);
342
464
  }
343
465
 
466
+ /** @internal */
344
467
  export function applyLaunchFieldValue(
345
468
  session: PendingLaunchSession,
346
469
  launcher: UiLauncherSummary,
@@ -352,7 +475,7 @@ export function applyLaunchFieldValue(
352
475
  return {
353
476
  ok: true,
354
477
  done: true,
355
- values: buildLaunchInput(session) as Record<string, LaunchFieldValue>,
478
+ values: buildLaunchInput(session),
356
479
  };
357
480
  }
358
481
  const parsed = normalizeFieldValue(field, value);
@@ -364,17 +487,10 @@ export function applyLaunchFieldValue(
364
487
  };
365
488
  }
366
489
  session.values[field.id] = parsed.value;
367
- session.fieldIndex += 1;
368
- const next = currentLaunchField(session, launcher);
369
- return next
370
- ? { ok: true, done: false, field: next }
371
- : {
372
- ok: true,
373
- done: true,
374
- values: buildLaunchInput(session) as Record<string, LaunchFieldValue>,
375
- };
490
+ return advanceLaunchField(session, launcher);
376
491
  }
377
492
 
493
+ /** @internal */
378
494
  export function moveLaunchSessionToValidationField(
379
495
  session: PendingLaunchSession,
380
496
  launcher: UiLauncherSummary,
@@ -398,8 +514,11 @@ function buildFieldOrder(launcher: UiLauncherSummary): string[] {
398
514
  ];
399
515
  }
400
516
 
517
+ /** @internal */
401
518
  export function buildLaunchReview(input: {
519
+ /** @internal */
402
520
  launcher: UiLauncherSummary;
521
+ /** @internal */
403
522
  session: PendingLaunchSession;
404
523
  }): string {
405
524
  const lines = [`Ready to start ${input.launcher.label}.`, "", "Launcher config:"];
@@ -427,9 +546,11 @@ function getLaunchModelStepOverride(
427
546
  step: LaunchModelStep,
428
547
  ): string | null {
429
548
  const config = buildLaunchModelConfig(session);
430
- return step.kind === "default"
431
- ? (trimToNull(config.defaultModelProfileId) ?? null)
432
- : (trimToNull(config.turnConfigs?.[step.turnId]?.modelProfileId) ?? null);
549
+ return trimToNull(
550
+ step.kind === "default"
551
+ ? config.defaultModelProfileId
552
+ : config.turnConfigs?.[step.turnId]?.modelProfileId,
553
+ );
433
554
  }
434
555
 
435
556
  function getLaunchModelStepPreview(
@@ -454,17 +575,10 @@ function launchModelStepError(
454
575
  };
455
576
  }
456
577
 
457
- function matchModelProfile(
458
- text: string,
459
- schema: LauncherModelConfigSchemaLike,
460
- ): LauncherModelConfigSchemaLike["availableProfiles"][number] | null {
461
- return matchByNumberValueOrLabel(text, schema.availableProfiles, (profile) => profile.id);
462
- }
463
-
464
578
  function setLaunchModelStepOverride(
465
579
  session: PendingLaunchSession,
466
580
  step: LaunchModelStep,
467
- modelProfileId: string,
581
+ modelProfileId: string | null,
468
582
  ): void {
469
583
  const current = buildLaunchModelConfig(session);
470
584
  if (step.kind === "default") {
@@ -473,7 +587,7 @@ function setLaunchModelStepOverride(
473
587
  defaultModelProfileId: modelProfileId,
474
588
  turnConfigs: current.turnConfigs ?? {},
475
589
  };
476
- } else {
590
+ } else if (modelProfileId !== null) {
477
591
  session.modelConfig = {
478
592
  ...current,
479
593
  turnConfigs: {
@@ -481,18 +595,6 @@ function setLaunchModelStepOverride(
481
595
  [step.turnId]: { modelProfileId },
482
596
  },
483
597
  };
484
- }
485
- session.modelConfigTouched = true;
486
- }
487
-
488
- function clearLaunchModelStepOverride(session: PendingLaunchSession, step: LaunchModelStep): void {
489
- const current = buildLaunchModelConfig(session);
490
- if (step.kind === "default") {
491
- session.modelConfig = {
492
- ...current,
493
- defaultModelProfileId: null,
494
- turnConfigs: current.turnConfigs ?? {},
495
- };
496
598
  } else {
497
599
  const turnConfigs = { ...(current.turnConfigs ?? {}) };
498
600
  delete turnConfigs[step.turnId];
@@ -580,7 +682,7 @@ function parseFieldText(
580
682
  return skipField(field, undefined);
581
683
  }
582
684
  if (field.kind === "select") {
583
- const matched = matchSelectOption(trimmed, options);
685
+ const matched = matchByNumberValueOrLabel(trimmed, options, (option) => option.value);
584
686
  if (matched) return { ok: true, setValue: true, value: matched.value };
585
687
  if (options.length > 0) {
586
688
  return { ok: false, error: `${field.label} must match one of the available options.` };
@@ -595,13 +697,6 @@ function parseFieldText(
595
697
  return { ok: true, setValue: true, value: normalized.value };
596
698
  }
597
699
 
598
- function matchSelectOption(
599
- text: string,
600
- options: readonly LauncherFieldOptionDefinition[],
601
- ): LauncherFieldOptionDefinition | null {
602
- return matchByNumberValueOrLabel(text, options, (option) => option.value);
603
- }
604
-
605
700
  function matchByNumberValueOrLabel<T extends { label: string }>(
606
701
  text: string,
607
702
  options: readonly T[],