@agimon-ai/doompi-loop 0.0.1-alpha.83 → 0.0.1-alpha.85

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.
@@ -1,15 +1,93 @@
1
+ import { defineTool } from "@agimon-ai/doompi-core/piExtension";
2
+ import { Type } from "typebox";
3
+ import { Check } from "typebox/value";
4
+ //#region src/constants/piLoop.ts
5
+ const PACKAGE_SOURCE = "@agimon-ai/doompi-loop";
6
+ const STATUS_KEY = "doom-loop";
7
+ const MODE_STATUS_ID = "loop.active";
8
+ const ACTIVE_MODE_COLOR = "warning";
9
+ const NOTIFY_INFO_LEVEL = "info";
10
+ const NOTIFY_WARNING_LEVEL = "warning";
11
+ //#endregion
1
12
  //#region src/constants/loop.ts
2
13
  const START_COMMAND_DESCRIPTION = "Start a registered loop";
3
14
  const LIST_COMMAND_DESCRIPTION = "List and stop active loops";
4
15
  const START_COMMAND_NAME = "loop";
5
16
  const LIST_COMMAND_NAME = "loops";
6
17
  //#endregion
18
+ //#region src/schemas/loopTools.ts
19
+ const LoopListSchema = Type.Object({}, { additionalProperties: false });
20
+ const LoopStartSchema = Type.Object({
21
+ launcherId: Type.String({
22
+ minLength: 1,
23
+ maxLength: 256
24
+ }),
25
+ instanceId: Type.Optional(Type.String({
26
+ minLength: 1,
27
+ maxLength: 256
28
+ })),
29
+ input: Type.Record(Type.String(), Type.Unknown())
30
+ }, { additionalProperties: false });
31
+ const LoopStopSchema = Type.Object({
32
+ instanceId: Type.String({
33
+ minLength: 1,
34
+ maxLength: 256
35
+ }),
36
+ reason: Type.Optional(Type.String({
37
+ minLength: 1,
38
+ maxLength: 512
39
+ }))
40
+ }, { additionalProperties: false });
41
+ const IntervalLoopSchema = Type.Object({
42
+ prompt: Type.String({
43
+ minLength: 1,
44
+ maxLength: 32768
45
+ }),
46
+ intervalSeconds: Type.Integer({
47
+ minimum: 30,
48
+ maximum: 3600
49
+ })
50
+ }, { additionalProperties: false });
51
+ const CronLoopSchema = Type.Object({
52
+ prompt: Type.String({
53
+ minLength: 1,
54
+ maxLength: 32768
55
+ }),
56
+ cron: Type.String({
57
+ minLength: 1,
58
+ maxLength: 256
59
+ }),
60
+ timezone: Type.Optional(Type.String({
61
+ minLength: 1,
62
+ maxLength: 128
63
+ }))
64
+ }, { additionalProperties: false });
65
+ function parseIntervalLoop(input) {
66
+ if (!Check(IntervalLoopSchema, input) || !input.prompt.trim()) throw new Error("Provide a non-empty prompt and an integer intervalSeconds between 30 and 3600.");
67
+ return {
68
+ ...input,
69
+ prompt: input.prompt.trim()
70
+ };
71
+ }
72
+ function parseCronLoop(input) {
73
+ if (!Check(CronLoopSchema, input) || !input.prompt.trim() || input.cron.trim().split(/\s+/u).length !== 5) throw new Error("Provide a non-empty prompt and a five-field cron expression, with an optional IANA timezone.");
74
+ const timezone = input.timezone ?? "UTC";
75
+ new Intl.DateTimeFormat("en", { timeZone: timezone }).format();
76
+ return {
77
+ ...input,
78
+ prompt: input.prompt.trim(),
79
+ cron: input.cron.trim(),
80
+ timezone
81
+ };
82
+ }
83
+ //#endregion
7
84
  //#region src/services/loopLaunchers/index.ts
8
85
  const MAX_ID_LENGTH = 256;
9
86
  const MAX_GENERATION_LENGTH = 256;
10
87
  const LAUNCHER_ID_LABEL = "loop launcher id";
11
88
  const INSTANCE_ID_LABEL = "loop instance id";
12
89
  function validId(value, label) {
90
+ if (typeof value !== "string") throw new TypeError(`Invalid ${label}.`);
13
91
  const normalized = value.trim();
14
92
  let hasControl = false;
15
93
  for (const character of normalized) {
@@ -97,7 +175,8 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
97
175
  id: definition.id,
98
176
  source: definition.source,
99
177
  label: definition.label,
100
- ...definition.description ? { description: definition.description } : {}
178
+ ...definition.description ? { description: definition.description } : {},
179
+ ...definition.inputSchema ? { inputSchema: definition.inputSchema } : {}
101
180
  })).sort((left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id));
102
181
  },
103
182
  listInstances() {
@@ -116,6 +195,7 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
116
195
  },
117
196
  async launch(launcherId, options) {
118
197
  ensureActive();
198
+ options?.signal?.throwIfAborted();
119
199
  const normalizedLauncherId = validId(launcherId, LAUNCHER_ID_LABEL);
120
200
  const launcher = launchers.get(normalizedLauncherId);
121
201
  if (!launcher) throw new Error(`Loop launcher '${normalizedLauncherId}' is unavailable.`);
@@ -127,12 +207,17 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
127
207
  abortController: new AbortController(),
128
208
  state: "starting"
129
209
  };
210
+ const abortSetup = () => entry.abortController.abort(options?.signal?.reason);
211
+ options?.signal?.addEventListener("abort", abortSetup, { once: true });
130
212
  instances.set(instanceId, entry);
131
213
  notify();
132
214
  try {
215
+ if (options?.interactive === false && !launcher.definition.inputSchema) throw new Error(`Loop launcher '${normalizedLauncherId}' requires manual setup in Activity.`);
133
216
  const handle = await launcher.definition.launch({
134
217
  instanceId,
135
- signal: entry.abortController.signal
218
+ signal: entry.abortController.signal,
219
+ ...options?.input === void 0 ? {} : { input: options.input },
220
+ ...options?.interactive === void 0 ? {} : { interactive: options.interactive }
136
221
  });
137
222
  const active = !disposed && instances.get(instanceId) === entry && !entry.abortController.signal.aborted;
138
223
  if (!handle) {
@@ -158,6 +243,8 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
158
243
  notify();
159
244
  if (cancelled) return void 0;
160
245
  throw error;
246
+ } finally {
247
+ options?.signal?.removeEventListener("abort", abortSetup);
161
248
  }
162
249
  },
163
250
  async stop(instanceId, reason) {
@@ -181,13 +268,74 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
181
268
  });
182
269
  }
183
270
  //#endregion
271
+ //#region src/services/loopTools/index.ts
272
+ function result(details) {
273
+ return {
274
+ content: [{
275
+ type: "text",
276
+ text: JSON.stringify(details, null, 2)
277
+ }],
278
+ details
279
+ };
280
+ }
281
+ function createLoopTools(launchers, assertEnabled) {
282
+ return [
283
+ defineTool({
284
+ name: "loop_list",
285
+ label: "List loops",
286
+ description: "List active session loops and available launcher types with their configuration schemas.",
287
+ parameters: LoopListSchema,
288
+ async execute(input, { signal }) {
289
+ assertEnabled();
290
+ signal?.throwIfAborted();
291
+ if (!Check(LoopListSchema, input)) throw new Error("loop_list takes no arguments.");
292
+ const service = launchers();
293
+ return result({
294
+ launchers: service.listLaunchers(),
295
+ instances: service.listInstances()
296
+ });
297
+ }
298
+ }),
299
+ defineTool({
300
+ name: "loop_start",
301
+ label: "Start loop",
302
+ description: "Start a session-scoped loop without operator dialogs. Read loop_list for launcher IDs and input schemas. Loops stop when the session shuts down.",
303
+ parameters: LoopStartSchema,
304
+ executionMode: "serial",
305
+ async execute(input, { signal }) {
306
+ assertEnabled();
307
+ signal?.throwIfAborted();
308
+ if (!Check(LoopStartSchema, input)) throw new Error("Provide launcherId, input, and optionally instanceId.");
309
+ return result(await launchers().launch(input.launcherId, {
310
+ ...input,
311
+ interactive: false,
312
+ signal
313
+ }) ?? { cancelled: true });
314
+ }
315
+ }),
316
+ defineTool({
317
+ name: "loop_stop",
318
+ label: "Stop loop",
319
+ description: "Stop one loop instance owned by the current session. Does not disable Loop mode or stop other loops.",
320
+ parameters: LoopStopSchema,
321
+ executionMode: "serial",
322
+ async execute(input, { signal }) {
323
+ assertEnabled();
324
+ signal?.throwIfAborted();
325
+ if (!Check(LoopStopSchema, input)) throw new Error("Provide instanceId and an optional reason.");
326
+ return result({ stopped: await launchers().stop(input.instanceId, input.reason ?? "Stopped by the agent.") });
327
+ }
328
+ })
329
+ ];
330
+ }
331
+ //#endregion
184
332
  //#region src/types/loopView.ts
185
333
  /** The browser-only status that carries active Loop instances into the activity dock. */
186
334
  const LOOP_VIEW_STATUS_KEY = "doom-loop-instances";
187
335
  new RegExp(String.raw`\u001b\[[0-9;]*m`, "gu");
188
336
  /** Projects runtime snapshots into the JSON status consumed by the web plugin. */
189
337
  function formatLoopStatusView(instances) {
190
- if (instances.length === 0) return void 0;
338
+ if (instances.length === 0) return "";
191
339
  return JSON.stringify(instances.map((instance) => ({
192
340
  instanceId: instance.instanceId,
193
341
  label: instance.label ?? instance.launcherLabel,
@@ -196,6 +344,6 @@ function formatLoopStatusView(instances) {
196
344
  })));
197
345
  }
198
346
  //#endregion
199
- export { LIST_COMMAND_NAME as a, LIST_COMMAND_DESCRIPTION as i, formatLoopStatusView as n, START_COMMAND_DESCRIPTION as o, createDoomLoopLaunchersService as r, START_COMMAND_NAME as s, LOOP_VIEW_STATUS_KEY as t };
347
+ export { PACKAGE_SOURCE as _, CronLoopSchema as a, parseIntervalLoop as c, START_COMMAND_DESCRIPTION as d, START_COMMAND_NAME as f, NOTIFY_WARNING_LEVEL as g, NOTIFY_INFO_LEVEL as h, createDoomLoopLaunchersService as i, LIST_COMMAND_DESCRIPTION as l, MODE_STATUS_ID as m, formatLoopStatusView as n, IntervalLoopSchema as o, ACTIVE_MODE_COLOR as p, createLoopTools as r, parseCronLoop as s, LOOP_VIEW_STATUS_KEY as t, LIST_COMMAND_NAME as u, STATUS_KEY as v };
200
348
 
201
- //# sourceMappingURL=loopView-CmuIEbUa.mjs.map
349
+ //# sourceMappingURL=loopView-BK4X_1UI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopView-BK4X_1UI.mjs","names":[],"sources":["../src/constants/piLoop.ts","../src/constants/loop.ts","../src/schemas/loopTools.ts","../src/services/loopLaunchers/index.ts","../src/services/loopTools/index.ts","../src/types/loopView.ts"],"sourcesContent":["export const PACKAGE_SOURCE = '@agimon-ai/doompi-loop';\nexport const LOOPS_GROUP_ORDER = 60;\nexport const STATUS_KEY = 'doom-loop';\nexport const MODE_STATUS_ID = 'loop.active';\nexport const ACTIVE_MODE_COLOR = 'warning';\nexport const NOTIFY_INFO_LEVEL = 'info';\nexport const NOTIFY_WARNING_LEVEL = 'warning';\n","export const START_COMMAND_DESCRIPTION = 'Start a registered loop';\nexport const LIST_COMMAND_DESCRIPTION = 'List and stop active loops';\nexport const START_COMMAND_NAME = 'loop';\nexport const LIST_COMMAND_NAME = 'loops';\n","import { type Static, Type } from 'typebox';\nimport { Check } from 'typebox/value';\n\nexport const LoopListSchema = Type.Object({}, { additionalProperties: false });\nexport const LoopStartSchema = Type.Object(\n {\n launcherId: Type.String({ minLength: 1, maxLength: 256 }),\n instanceId: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),\n input: Type.Record(Type.String(), Type.Unknown()),\n },\n { additionalProperties: false },\n);\nexport const LoopStopSchema = Type.Object(\n {\n instanceId: Type.String({ minLength: 1, maxLength: 256 }),\n reason: Type.Optional(Type.String({ minLength: 1, maxLength: 512 })),\n },\n { additionalProperties: false },\n);\n\nexport const IntervalLoopSchema = Type.Object(\n {\n prompt: Type.String({ minLength: 1, maxLength: 32768 }),\n intervalSeconds: Type.Integer({ minimum: 30, maximum: 3600 }),\n },\n { additionalProperties: false },\n);\nexport const CronLoopSchema = Type.Object(\n {\n prompt: Type.String({ minLength: 1, maxLength: 32768 }),\n cron: Type.String({ minLength: 1, maxLength: 256 }),\n timezone: Type.Optional(Type.String({ minLength: 1, maxLength: 128 })),\n },\n { additionalProperties: false },\n);\nexport type IntervalLoopInput = Static<typeof IntervalLoopSchema>;\nexport type CronLoopInput = Static<typeof CronLoopSchema>;\n\nexport function parseIntervalLoop(input: unknown): IntervalLoopInput {\n if (!Check(IntervalLoopSchema, input) || !input.prompt.trim()) {\n throw new Error('Provide a non-empty prompt and an integer intervalSeconds between 30 and 3600.');\n }\n return { ...input, prompt: input.prompt.trim() };\n}\n\nexport function parseCronLoop(input: unknown): CronLoopInput {\n if (!Check(CronLoopSchema, input) || !input.prompt.trim() || input.cron.trim().split(/\\s+/u).length !== 5) {\n throw new Error('Provide a non-empty prompt and a five-field cron expression, with an optional IANA timezone.');\n }\n const timezone = input.timezone ?? 'UTC';\n new Intl.DateTimeFormat('en', { timeZone: timezone }).format();\n return { ...input, prompt: input.prompt.trim(), cron: input.cron.trim(), timezone };\n}\n","import type {\n DoomLoopLaunchersService,\n LoopInstanceSnapshot,\n LoopLauncherDefinition,\n LoopLauncherRegistration,\n StoppableLoop,\n} from '../../schemas/loopLaunchers';\n\nconst MAX_ID_LENGTH = 256;\nconst MAX_GENERATION_LENGTH = 256;\nconst LAUNCHER_ID_LABEL = 'loop launcher id';\nconst INSTANCE_ID_LABEL = 'loop instance id';\n\ninterface LauncherEntry {\n readonly token: symbol;\n readonly definition: LoopLauncherDefinition;\n}\n\ninterface InstanceEntry {\n readonly instanceId: string;\n readonly launcher: LauncherEntry;\n readonly abortController: AbortController;\n state: LoopInstanceSnapshot['state'];\n handle?: StoppableLoop;\n startedAt?: string;\n}\n\nexport interface LoopLaunchersDependencies {\n readonly generation: string;\n readonly createInstanceId: () => string;\n readonly timestamp: () => string;\n}\n\nfunction validId(value: string, label: string): string {\n if (typeof value !== 'string') throw new TypeError(`Invalid ${label}.`);\n const normalized = value.trim();\n let hasControl = false;\n for (const character of normalized) {\n const code = character.codePointAt(0);\n if (code !== undefined && (code <= 0x1f || code === 0x7f)) {\n hasControl = true;\n break;\n }\n }\n if (!normalized || normalized.length > MAX_ID_LENGTH || hasControl) throw new Error(`Invalid ${label}.`);\n return normalized;\n}\n\nfunction snapshot(entry: InstanceEntry): LoopInstanceSnapshot {\n return {\n instanceId: entry.instanceId,\n launcherId: entry.launcher.definition.id,\n launcherLabel: entry.launcher.definition.label,\n ...(entry.handle?.label ? { label: entry.handle.label } : {}),\n ...(entry.handle?.detail ? { detail: entry.handle.detail } : {}),\n state: entry.state,\n ...(entry.startedAt ? { startedAt: entry.startedAt } : {}),\n };\n}\n\n/** Creates the provider-owned launcher registry for one active Doom session. */\nexport function createDoomLoopLaunchersService({\n generation,\n createInstanceId,\n timestamp,\n}: LoopLaunchersDependencies): DoomLoopLaunchersService {\n if (!generation || generation.length > MAX_GENERATION_LENGTH) {\n throw new TypeError('Doom loop launchers require a valid generation.');\n }\n\n const launchers = new Map<string, LauncherEntry>();\n const instances = new Map<string, InstanceEntry>();\n const listeners = new Set<() => void>();\n let registrationSequence = 0;\n let disposed = false;\n\n const ensureActive = (): void => {\n if (disposed) throw new Error('The Doom loop-launchers service is disposed.');\n };\n const notify = (): void => {\n for (const listener of listeners) listener();\n };\n const stopEntry = async (entry: InstanceEntry, reason?: string): Promise<void> => {\n if (instances.get(entry.instanceId) !== entry) return;\n entry.state = 'stopping';\n entry.abortController.abort(reason);\n notify();\n try {\n await entry.handle?.stop(reason);\n } finally {\n if (instances.get(entry.instanceId) === entry) instances.delete(entry.instanceId);\n notify();\n }\n };\n\n const service: DoomLoopLaunchersService = {\n generation,\n register(definition): LoopLauncherRegistration {\n ensureActive();\n const id = validId(definition.id, LAUNCHER_ID_LABEL);\n if (launchers.has(id)) throw new Error(`Loop launcher '${id}' is already registered.`);\n const token = Symbol(id);\n const entry: LauncherEntry = { token, definition: { ...definition, id } };\n launchers.set(id, entry);\n registrationSequence += 1;\n notify();\n let registrationDisposed = false;\n return Object.freeze({\n id,\n generation: `${generation}:launcher:${registrationSequence}`,\n async dispose(reason = 'Loop launcher disposed.'): Promise<void> {\n if (registrationDisposed) return;\n registrationDisposed = true;\n if (launchers.get(id)?.token !== token) return;\n launchers.delete(id);\n const owned = [...instances.values()].filter((instance) => instance.launcher.token === token);\n await Promise.allSettled(owned.map((instance) => stopEntry(instance, reason)));\n notify();\n },\n });\n },\n listLaunchers() {\n ensureActive();\n return [...launchers.values()]\n .map(({ definition }) => ({\n id: definition.id,\n source: definition.source,\n label: definition.label,\n ...(definition.description ? { description: definition.description } : {}),\n ...(definition.inputSchema ? { inputSchema: definition.inputSchema } : {}),\n }))\n .sort((left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id));\n },\n listInstances() {\n ensureActive();\n return [...instances.values()]\n .map(snapshot)\n .sort((left, right) => left.instanceId.localeCompare(right.instanceId));\n },\n subscribe(listener) {\n ensureActive();\n listeners.add(listener);\n let subscribed = true;\n return () => {\n if (!subscribed) return;\n subscribed = false;\n listeners.delete(listener);\n };\n },\n async launch(launcherId, options) {\n ensureActive();\n options?.signal?.throwIfAborted();\n const normalizedLauncherId = validId(launcherId, LAUNCHER_ID_LABEL);\n const launcher = launchers.get(normalizedLauncherId);\n if (!launcher) throw new Error(`Loop launcher '${normalizedLauncherId}' is unavailable.`);\n const instanceId = validId(options?.instanceId ?? createInstanceId(), INSTANCE_ID_LABEL);\n if (instances.has(instanceId)) throw new Error(`Loop instance '${instanceId}' already exists.`);\n const entry: InstanceEntry = { instanceId, launcher, abortController: new AbortController(), state: 'starting' };\n const abortSetup = (): void => entry.abortController.abort(options?.signal?.reason);\n options?.signal?.addEventListener('abort', abortSetup, { once: true });\n instances.set(instanceId, entry);\n notify();\n try {\n if (options?.interactive === false && !launcher.definition.inputSchema) {\n throw new Error(`Loop launcher '${normalizedLauncherId}' requires manual setup in Activity.`);\n }\n const handle = await launcher.definition.launch({\n instanceId,\n signal: entry.abortController.signal,\n ...(options?.input === undefined ? {} : { input: options.input }),\n ...(options?.interactive === undefined ? {} : { interactive: options.interactive }),\n });\n const active = !disposed && instances.get(instanceId) === entry && !entry.abortController.signal.aborted;\n if (!handle) {\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n return undefined;\n }\n if (!active || handle.instanceId !== instanceId) {\n await handle.stop(active ? 'Loop launcher returned a mismatched instance id.' : 'Loop launch was cancelled.');\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n if (active) throw new Error(`Loop launcher '${normalizedLauncherId}' returned a mismatched instance id.`);\n return undefined;\n }\n entry.handle = handle;\n entry.state = 'running';\n entry.startedAt = timestamp();\n notify();\n return snapshot(entry);\n } catch (error) {\n const cancelled = entry.abortController.signal.aborted || disposed;\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n if (cancelled) return undefined;\n throw error;\n } finally {\n options?.signal?.removeEventListener('abort', abortSetup);\n }\n },\n async stop(instanceId, reason) {\n ensureActive();\n const entry = instances.get(validId(instanceId, INSTANCE_ID_LABEL));\n if (!entry) return false;\n await stopEntry(entry, reason);\n return true;\n },\n async stopAll(reason) {\n if (disposed && instances.size === 0) return;\n await Promise.allSettled([...instances.values()].map((entry) => stopEntry(entry, reason)));\n },\n async dispose(reason = 'Doom loop-launchers service disposed.') {\n if (disposed) return;\n disposed = true;\n launchers.clear();\n await Promise.allSettled([...instances.values()].map((entry) => stopEntry(entry, reason)));\n listeners.clear();\n },\n };\n\n return Object.freeze(service);\n}\n","import { defineTool, type DoomPluginTool, type DoomPluginToolResult } from '@agimon-ai/doompi-core/piExtension';\nimport { Check } from 'typebox/value';\n\nimport type { DoomLoopLaunchersService } from '../../schemas/loopLaunchers';\nimport { LoopListSchema, LoopStartSchema, LoopStopSchema } from '../../schemas/loopTools';\n\nfunction result(details: unknown): DoomPluginToolResult {\n return { content: [{ type: 'text', text: JSON.stringify(details, null, 2) }], details };\n}\n\nexport function createLoopTools(\n launchers: () => DoomLoopLaunchersService,\n assertEnabled: () => void,\n): readonly DoomPluginTool[] {\n return [\n defineTool({\n name: 'loop_list',\n label: 'List loops',\n description: 'List active session loops and available launcher types with their configuration schemas.',\n parameters: LoopListSchema,\n async execute(input, { signal }) {\n assertEnabled();\n signal?.throwIfAborted();\n if (!Check(LoopListSchema, input)) throw new Error('loop_list takes no arguments.');\n const service = launchers();\n return result({ launchers: service.listLaunchers(), instances: service.listInstances() });\n },\n }),\n defineTool({\n name: 'loop_start',\n label: 'Start loop',\n description:\n 'Start a session-scoped loop without operator dialogs. Read loop_list for launcher IDs and input schemas. Loops stop when the session shuts down.',\n parameters: LoopStartSchema,\n executionMode: 'serial',\n async execute(input, { signal }) {\n assertEnabled();\n signal?.throwIfAborted();\n if (!Check(LoopStartSchema, input)) throw new Error('Provide launcherId, input, and optionally instanceId.');\n return result(\n (await launchers().launch(input.launcherId, { ...input, interactive: false, signal })) ?? { cancelled: true },\n );\n },\n }),\n defineTool({\n name: 'loop_stop',\n label: 'Stop loop',\n description:\n 'Stop one loop instance owned by the current session. Does not disable Loop mode or stop other loops.',\n parameters: LoopStopSchema,\n executionMode: 'serial',\n async execute(input, { signal }) {\n assertEnabled();\n signal?.throwIfAborted();\n if (!Check(LoopStopSchema, input)) throw new Error('Provide instanceId and an optional reason.');\n return result({ stopped: await launchers().stop(input.instanceId, input.reason ?? 'Stopped by the agent.') });\n },\n }),\n ];\n}\n","/** The browser-only status that carries active Loop instances into the activity dock. */\nexport const LOOP_VIEW_STATUS_KEY = 'doom-loop-instances';\n\nexport type LoopStatusState = 'starting' | 'running' | 'stopping';\n\n/** The small, serializable Loop view the cockpit needs for one activity row. */\nexport interface LoopStatusItem {\n readonly instanceId: string;\n readonly label: string;\n readonly detail: string;\n readonly state: LoopStatusState;\n}\n\ninterface LoopStatusSource {\n readonly instanceId: string;\n readonly launcherLabel: string;\n readonly label?: string;\n readonly detail?: string;\n readonly state: LoopStatusState;\n}\n\nconst ANSI = new RegExp(String.raw`\\u001b\\[[0-9;]*m`, 'gu');\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isState(value: unknown): value is LoopStatusState {\n return value === 'starting' || value === 'running' || value === 'stopping';\n}\n\n/** Projects runtime snapshots into the JSON status consumed by the web plugin. */\nexport function formatLoopStatusView(instances: readonly LoopStatusSource[]): string {\n if (instances.length === 0) return '';\n return JSON.stringify(\n instances.map((instance) => ({\n instanceId: instance.instanceId,\n label: instance.label ?? instance.launcherLabel,\n detail: instance.detail ?? instance.instanceId,\n state: instance.state,\n })),\n );\n}\n\n/** Reads a Loop status without letting malformed session data crash the activity dock. */\nexport function parseLoopStatusView(raw: string | undefined): LoopStatusItem[] | undefined {\n if (raw === undefined) return undefined;\n const text = raw.replace(ANSI, '').trim();\n if (text === '') return undefined;\n\n try {\n const value: unknown = JSON.parse(text);\n if (!Array.isArray(value) || value.length === 0) return undefined;\n const items: LoopStatusItem[] = [];\n for (const item of value) {\n if (\n !isRecord(item) ||\n typeof item.instanceId !== 'string' ||\n item.instanceId.trim() === '' ||\n typeof item.label !== 'string' ||\n item.label.trim() === '' ||\n typeof item.detail !== 'string' ||\n !isState(item.state)\n ) {\n return undefined;\n }\n items.push({ instanceId: item.instanceId, label: item.label, detail: item.detail, state: item.state });\n }\n return items;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;AAAA,MAAa,iBAAiB;AAE9B,MAAa,aAAa;AAC1B,MAAa,iBAAiB;AAC9B,MAAa,oBAAoB;AACjC,MAAa,oBAAoB;AACjC,MAAa,uBAAuB;;;ACNpC,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;;;ACAjC,MAAa,iBAAiB,KAAK,OAAO,CAAC,GAAG,EAAE,sBAAsB,MAAM,CAAC;AAC7E,MAAa,kBAAkB,KAAK,OAClC;CACE,YAAY,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC;CACxD,YAAY,KAAK,SAAS,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC,CAAC;CACvE,OAAO,KAAK,OAAO,KAAK,OAAO,GAAG,KAAK,QAAQ,CAAC;AAClD,GACA,EAAE,sBAAsB,MAAM,CAChC;AACA,MAAa,iBAAiB,KAAK,OACjC;CACE,YAAY,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC;CACxD,QAAQ,KAAK,SAAS,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC,CAAC;AACrE,GACA,EAAE,sBAAsB,MAAM,CAChC;AAEA,MAAa,qBAAqB,KAAK,OACrC;CACE,QAAQ,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAM,CAAC;CACtD,iBAAiB,KAAK,QAAQ;EAAE,SAAS;EAAI,SAAS;CAAK,CAAC;AAC9D,GACA,EAAE,sBAAsB,MAAM,CAChC;AACA,MAAa,iBAAiB,KAAK,OACjC;CACE,QAAQ,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAM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BAAqB,WAAgD;CACnF,IAAI,UAAU,WAAW,GAAG,OAAO;CACnC,OAAO,KAAK,UACV,UAAU,KAAK,cAAc;EAC3B,YAAY,SAAS;EACrB,OAAO,SAAS,SAAS,SAAS;EAClC,QAAQ,SAAS,UAAU,SAAS;EACpC,OAAO,SAAS;CAClB,EAAE,CACJ;AACF"}
@@ -1,15 +1,93 @@
1
+ let _agimon_ai_doompi_core_piExtension = require("@agimon-ai/doompi-core/piExtension");
2
+ let typebox = require("typebox");
3
+ let typebox_value = require("typebox/value");
4
+ //#region src/constants/piLoop.ts
5
+ const PACKAGE_SOURCE = "@agimon-ai/doompi-loop";
6
+ const STATUS_KEY = "doom-loop";
7
+ const MODE_STATUS_ID = "loop.active";
8
+ const ACTIVE_MODE_COLOR = "warning";
9
+ const NOTIFY_INFO_LEVEL = "info";
10
+ const NOTIFY_WARNING_LEVEL = "warning";
11
+ //#endregion
1
12
  //#region src/constants/loop.ts
2
13
  const START_COMMAND_DESCRIPTION = "Start a registered loop";
3
14
  const LIST_COMMAND_DESCRIPTION = "List and stop active loops";
4
15
  const START_COMMAND_NAME = "loop";
5
16
  const LIST_COMMAND_NAME = "loops";
6
17
  //#endregion
18
+ //#region src/schemas/loopTools.ts
19
+ const LoopListSchema = typebox.Type.Object({}, { additionalProperties: false });
20
+ const LoopStartSchema = typebox.Type.Object({
21
+ launcherId: typebox.Type.String({
22
+ minLength: 1,
23
+ maxLength: 256
24
+ }),
25
+ instanceId: typebox.Type.Optional(typebox.Type.String({
26
+ minLength: 1,
27
+ maxLength: 256
28
+ })),
29
+ input: typebox.Type.Record(typebox.Type.String(), typebox.Type.Unknown())
30
+ }, { additionalProperties: false });
31
+ const LoopStopSchema = typebox.Type.Object({
32
+ instanceId: typebox.Type.String({
33
+ minLength: 1,
34
+ maxLength: 256
35
+ }),
36
+ reason: typebox.Type.Optional(typebox.Type.String({
37
+ minLength: 1,
38
+ maxLength: 512
39
+ }))
40
+ }, { additionalProperties: false });
41
+ const IntervalLoopSchema = typebox.Type.Object({
42
+ prompt: typebox.Type.String({
43
+ minLength: 1,
44
+ maxLength: 32768
45
+ }),
46
+ intervalSeconds: typebox.Type.Integer({
47
+ minimum: 30,
48
+ maximum: 3600
49
+ })
50
+ }, { additionalProperties: false });
51
+ const CronLoopSchema = typebox.Type.Object({
52
+ prompt: typebox.Type.String({
53
+ minLength: 1,
54
+ maxLength: 32768
55
+ }),
56
+ cron: typebox.Type.String({
57
+ minLength: 1,
58
+ maxLength: 256
59
+ }),
60
+ timezone: typebox.Type.Optional(typebox.Type.String({
61
+ minLength: 1,
62
+ maxLength: 128
63
+ }))
64
+ }, { additionalProperties: false });
65
+ function parseIntervalLoop(input) {
66
+ if (!(0, typebox_value.Check)(IntervalLoopSchema, input) || !input.prompt.trim()) throw new Error("Provide a non-empty prompt and an integer intervalSeconds between 30 and 3600.");
67
+ return {
68
+ ...input,
69
+ prompt: input.prompt.trim()
70
+ };
71
+ }
72
+ function parseCronLoop(input) {
73
+ if (!(0, typebox_value.Check)(CronLoopSchema, input) || !input.prompt.trim() || input.cron.trim().split(/\s+/u).length !== 5) throw new Error("Provide a non-empty prompt and a five-field cron expression, with an optional IANA timezone.");
74
+ const timezone = input.timezone ?? "UTC";
75
+ new Intl.DateTimeFormat("en", { timeZone: timezone }).format();
76
+ return {
77
+ ...input,
78
+ prompt: input.prompt.trim(),
79
+ cron: input.cron.trim(),
80
+ timezone
81
+ };
82
+ }
83
+ //#endregion
7
84
  //#region src/services/loopLaunchers/index.ts
8
85
  const MAX_ID_LENGTH = 256;
9
86
  const MAX_GENERATION_LENGTH = 256;
10
87
  const LAUNCHER_ID_LABEL = "loop launcher id";
11
88
  const INSTANCE_ID_LABEL = "loop instance id";
12
89
  function validId(value, label) {
90
+ if (typeof value !== "string") throw new TypeError(`Invalid ${label}.`);
13
91
  const normalized = value.trim();
14
92
  let hasControl = false;
15
93
  for (const character of normalized) {
@@ -97,7 +175,8 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
97
175
  id: definition.id,
98
176
  source: definition.source,
99
177
  label: definition.label,
100
- ...definition.description ? { description: definition.description } : {}
178
+ ...definition.description ? { description: definition.description } : {},
179
+ ...definition.inputSchema ? { inputSchema: definition.inputSchema } : {}
101
180
  })).sort((left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id));
102
181
  },
103
182
  listInstances() {
@@ -116,6 +195,7 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
116
195
  },
117
196
  async launch(launcherId, options) {
118
197
  ensureActive();
198
+ options?.signal?.throwIfAborted();
119
199
  const normalizedLauncherId = validId(launcherId, LAUNCHER_ID_LABEL);
120
200
  const launcher = launchers.get(normalizedLauncherId);
121
201
  if (!launcher) throw new Error(`Loop launcher '${normalizedLauncherId}' is unavailable.`);
@@ -127,12 +207,17 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
127
207
  abortController: new AbortController(),
128
208
  state: "starting"
129
209
  };
210
+ const abortSetup = () => entry.abortController.abort(options?.signal?.reason);
211
+ options?.signal?.addEventListener("abort", abortSetup, { once: true });
130
212
  instances.set(instanceId, entry);
131
213
  notify();
132
214
  try {
215
+ if (options?.interactive === false && !launcher.definition.inputSchema) throw new Error(`Loop launcher '${normalizedLauncherId}' requires manual setup in Activity.`);
133
216
  const handle = await launcher.definition.launch({
134
217
  instanceId,
135
- signal: entry.abortController.signal
218
+ signal: entry.abortController.signal,
219
+ ...options?.input === void 0 ? {} : { input: options.input },
220
+ ...options?.interactive === void 0 ? {} : { interactive: options.interactive }
136
221
  });
137
222
  const active = !disposed && instances.get(instanceId) === entry && !entry.abortController.signal.aborted;
138
223
  if (!handle) {
@@ -158,6 +243,8 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
158
243
  notify();
159
244
  if (cancelled) return void 0;
160
245
  throw error;
246
+ } finally {
247
+ options?.signal?.removeEventListener("abort", abortSetup);
161
248
  }
162
249
  },
163
250
  async stop(instanceId, reason) {
@@ -181,13 +268,74 @@ function createDoomLoopLaunchersService({ generation, createInstanceId, timestam
181
268
  });
182
269
  }
183
270
  //#endregion
271
+ //#region src/services/loopTools/index.ts
272
+ function result(details) {
273
+ return {
274
+ content: [{
275
+ type: "text",
276
+ text: JSON.stringify(details, null, 2)
277
+ }],
278
+ details
279
+ };
280
+ }
281
+ function createLoopTools(launchers, assertEnabled) {
282
+ return [
283
+ (0, _agimon_ai_doompi_core_piExtension.defineTool)({
284
+ name: "loop_list",
285
+ label: "List loops",
286
+ description: "List active session loops and available launcher types with their configuration schemas.",
287
+ parameters: LoopListSchema,
288
+ async execute(input, { signal }) {
289
+ assertEnabled();
290
+ signal?.throwIfAborted();
291
+ if (!(0, typebox_value.Check)(LoopListSchema, input)) throw new Error("loop_list takes no arguments.");
292
+ const service = launchers();
293
+ return result({
294
+ launchers: service.listLaunchers(),
295
+ instances: service.listInstances()
296
+ });
297
+ }
298
+ }),
299
+ (0, _agimon_ai_doompi_core_piExtension.defineTool)({
300
+ name: "loop_start",
301
+ label: "Start loop",
302
+ description: "Start a session-scoped loop without operator dialogs. Read loop_list for launcher IDs and input schemas. Loops stop when the session shuts down.",
303
+ parameters: LoopStartSchema,
304
+ executionMode: "serial",
305
+ async execute(input, { signal }) {
306
+ assertEnabled();
307
+ signal?.throwIfAborted();
308
+ if (!(0, typebox_value.Check)(LoopStartSchema, input)) throw new Error("Provide launcherId, input, and optionally instanceId.");
309
+ return result(await launchers().launch(input.launcherId, {
310
+ ...input,
311
+ interactive: false,
312
+ signal
313
+ }) ?? { cancelled: true });
314
+ }
315
+ }),
316
+ (0, _agimon_ai_doompi_core_piExtension.defineTool)({
317
+ name: "loop_stop",
318
+ label: "Stop loop",
319
+ description: "Stop one loop instance owned by the current session. Does not disable Loop mode or stop other loops.",
320
+ parameters: LoopStopSchema,
321
+ executionMode: "serial",
322
+ async execute(input, { signal }) {
323
+ assertEnabled();
324
+ signal?.throwIfAborted();
325
+ if (!(0, typebox_value.Check)(LoopStopSchema, input)) throw new Error("Provide instanceId and an optional reason.");
326
+ return result({ stopped: await launchers().stop(input.instanceId, input.reason ?? "Stopped by the agent.") });
327
+ }
328
+ })
329
+ ];
330
+ }
331
+ //#endregion
184
332
  //#region src/types/loopView.ts
185
333
  /** The browser-only status that carries active Loop instances into the activity dock. */
186
334
  const LOOP_VIEW_STATUS_KEY = "doom-loop-instances";
187
335
  new RegExp(String.raw`\u001b\[[0-9;]*m`, "gu");
188
336
  /** Projects runtime snapshots into the JSON status consumed by the web plugin. */
189
337
  function formatLoopStatusView(instances) {
190
- if (instances.length === 0) return void 0;
338
+ if (instances.length === 0) return "";
191
339
  return JSON.stringify(instances.map((instance) => ({
192
340
  instanceId: instance.instanceId,
193
341
  label: instance.label ?? instance.launcherLabel,
@@ -196,6 +344,24 @@ function formatLoopStatusView(instances) {
196
344
  })));
197
345
  }
198
346
  //#endregion
347
+ Object.defineProperty(exports, "ACTIVE_MODE_COLOR", {
348
+ enumerable: true,
349
+ get: function() {
350
+ return ACTIVE_MODE_COLOR;
351
+ }
352
+ });
353
+ Object.defineProperty(exports, "CronLoopSchema", {
354
+ enumerable: true,
355
+ get: function() {
356
+ return CronLoopSchema;
357
+ }
358
+ });
359
+ Object.defineProperty(exports, "IntervalLoopSchema", {
360
+ enumerable: true,
361
+ get: function() {
362
+ return IntervalLoopSchema;
363
+ }
364
+ });
199
365
  Object.defineProperty(exports, "LIST_COMMAND_DESCRIPTION", {
200
366
  enumerable: true,
201
367
  get: function() {
@@ -214,6 +380,30 @@ Object.defineProperty(exports, "LOOP_VIEW_STATUS_KEY", {
214
380
  return LOOP_VIEW_STATUS_KEY;
215
381
  }
216
382
  });
383
+ Object.defineProperty(exports, "MODE_STATUS_ID", {
384
+ enumerable: true,
385
+ get: function() {
386
+ return MODE_STATUS_ID;
387
+ }
388
+ });
389
+ Object.defineProperty(exports, "NOTIFY_INFO_LEVEL", {
390
+ enumerable: true,
391
+ get: function() {
392
+ return NOTIFY_INFO_LEVEL;
393
+ }
394
+ });
395
+ Object.defineProperty(exports, "NOTIFY_WARNING_LEVEL", {
396
+ enumerable: true,
397
+ get: function() {
398
+ return NOTIFY_WARNING_LEVEL;
399
+ }
400
+ });
401
+ Object.defineProperty(exports, "PACKAGE_SOURCE", {
402
+ enumerable: true,
403
+ get: function() {
404
+ return PACKAGE_SOURCE;
405
+ }
406
+ });
217
407
  Object.defineProperty(exports, "START_COMMAND_DESCRIPTION", {
218
408
  enumerable: true,
219
409
  get: function() {
@@ -226,17 +416,41 @@ Object.defineProperty(exports, "START_COMMAND_NAME", {
226
416
  return START_COMMAND_NAME;
227
417
  }
228
418
  });
419
+ Object.defineProperty(exports, "STATUS_KEY", {
420
+ enumerable: true,
421
+ get: function() {
422
+ return STATUS_KEY;
423
+ }
424
+ });
229
425
  Object.defineProperty(exports, "createDoomLoopLaunchersService", {
230
426
  enumerable: true,
231
427
  get: function() {
232
428
  return createDoomLoopLaunchersService;
233
429
  }
234
430
  });
431
+ Object.defineProperty(exports, "createLoopTools", {
432
+ enumerable: true,
433
+ get: function() {
434
+ return createLoopTools;
435
+ }
436
+ });
235
437
  Object.defineProperty(exports, "formatLoopStatusView", {
236
438
  enumerable: true,
237
439
  get: function() {
238
440
  return formatLoopStatusView;
239
441
  }
240
442
  });
443
+ Object.defineProperty(exports, "parseCronLoop", {
444
+ enumerable: true,
445
+ get: function() {
446
+ return parseCronLoop;
447
+ }
448
+ });
449
+ Object.defineProperty(exports, "parseIntervalLoop", {
450
+ enumerable: true,
451
+ get: function() {
452
+ return parseIntervalLoop;
453
+ }
454
+ });
241
455
 
242
- //# sourceMappingURL=loopView-CLIBhqYC.cjs.map
456
+ //# sourceMappingURL=loopView-C_OPuy8L.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopView-C_OPuy8L.cjs","names":["Type","Check","defineTool","Check"],"sources":["../src/constants/piLoop.ts","../src/constants/loop.ts","../src/schemas/loopTools.ts","../src/services/loopLaunchers/index.ts","../src/services/loopTools/index.ts","../src/types/loopView.ts"],"sourcesContent":["export const PACKAGE_SOURCE = '@agimon-ai/doompi-loop';\nexport const LOOPS_GROUP_ORDER = 60;\nexport const STATUS_KEY = 'doom-loop';\nexport const MODE_STATUS_ID = 'loop.active';\nexport const ACTIVE_MODE_COLOR = 'warning';\nexport const NOTIFY_INFO_LEVEL = 'info';\nexport const NOTIFY_WARNING_LEVEL = 'warning';\n","export const START_COMMAND_DESCRIPTION = 'Start a registered loop';\nexport const LIST_COMMAND_DESCRIPTION = 'List and stop active loops';\nexport const START_COMMAND_NAME = 'loop';\nexport const LIST_COMMAND_NAME = 'loops';\n","import { type Static, Type } from 'typebox';\nimport { Check } from 'typebox/value';\n\nexport const LoopListSchema = Type.Object({}, { additionalProperties: false });\nexport const LoopStartSchema = Type.Object(\n {\n launcherId: Type.String({ minLength: 1, maxLength: 256 }),\n instanceId: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),\n input: Type.Record(Type.String(), Type.Unknown()),\n },\n { additionalProperties: false },\n);\nexport const LoopStopSchema = Type.Object(\n {\n instanceId: Type.String({ minLength: 1, maxLength: 256 }),\n reason: Type.Optional(Type.String({ minLength: 1, maxLength: 512 })),\n },\n { additionalProperties: false },\n);\n\nexport const IntervalLoopSchema = Type.Object(\n {\n prompt: Type.String({ minLength: 1, maxLength: 32768 }),\n intervalSeconds: Type.Integer({ minimum: 30, maximum: 3600 }),\n },\n { additionalProperties: false },\n);\nexport const CronLoopSchema = Type.Object(\n {\n prompt: Type.String({ minLength: 1, maxLength: 32768 }),\n cron: Type.String({ minLength: 1, maxLength: 256 }),\n timezone: Type.Optional(Type.String({ minLength: 1, maxLength: 128 })),\n },\n { additionalProperties: false },\n);\nexport type IntervalLoopInput = Static<typeof IntervalLoopSchema>;\nexport type CronLoopInput = Static<typeof CronLoopSchema>;\n\nexport function parseIntervalLoop(input: unknown): IntervalLoopInput {\n if (!Check(IntervalLoopSchema, input) || !input.prompt.trim()) {\n throw new Error('Provide a non-empty prompt and an integer intervalSeconds between 30 and 3600.');\n }\n return { ...input, prompt: input.prompt.trim() };\n}\n\nexport function parseCronLoop(input: unknown): CronLoopInput {\n if (!Check(CronLoopSchema, input) || !input.prompt.trim() || input.cron.trim().split(/\\s+/u).length !== 5) {\n throw new Error('Provide a non-empty prompt and a five-field cron expression, with an optional IANA timezone.');\n }\n const timezone = input.timezone ?? 'UTC';\n new Intl.DateTimeFormat('en', { timeZone: timezone }).format();\n return { ...input, prompt: input.prompt.trim(), cron: input.cron.trim(), timezone };\n}\n","import type {\n DoomLoopLaunchersService,\n LoopInstanceSnapshot,\n LoopLauncherDefinition,\n LoopLauncherRegistration,\n StoppableLoop,\n} from '../../schemas/loopLaunchers';\n\nconst MAX_ID_LENGTH = 256;\nconst MAX_GENERATION_LENGTH = 256;\nconst LAUNCHER_ID_LABEL = 'loop launcher id';\nconst INSTANCE_ID_LABEL = 'loop instance id';\n\ninterface LauncherEntry {\n readonly token: symbol;\n readonly definition: LoopLauncherDefinition;\n}\n\ninterface InstanceEntry {\n readonly instanceId: string;\n readonly launcher: LauncherEntry;\n readonly abortController: AbortController;\n state: LoopInstanceSnapshot['state'];\n handle?: StoppableLoop;\n startedAt?: string;\n}\n\nexport interface LoopLaunchersDependencies {\n readonly generation: string;\n readonly createInstanceId: () => string;\n readonly timestamp: () => string;\n}\n\nfunction validId(value: string, label: string): string {\n if (typeof value !== 'string') throw new TypeError(`Invalid ${label}.`);\n const normalized = value.trim();\n let hasControl = false;\n for (const character of normalized) {\n const code = character.codePointAt(0);\n if (code !== undefined && (code <= 0x1f || code === 0x7f)) {\n hasControl = true;\n break;\n }\n }\n if (!normalized || normalized.length > MAX_ID_LENGTH || hasControl) throw new Error(`Invalid ${label}.`);\n return normalized;\n}\n\nfunction snapshot(entry: InstanceEntry): LoopInstanceSnapshot {\n return {\n instanceId: entry.instanceId,\n launcherId: entry.launcher.definition.id,\n launcherLabel: entry.launcher.definition.label,\n ...(entry.handle?.label ? { label: entry.handle.label } : {}),\n ...(entry.handle?.detail ? { detail: entry.handle.detail } : {}),\n state: entry.state,\n ...(entry.startedAt ? { startedAt: entry.startedAt } : {}),\n };\n}\n\n/** Creates the provider-owned launcher registry for one active Doom session. */\nexport function createDoomLoopLaunchersService({\n generation,\n createInstanceId,\n timestamp,\n}: LoopLaunchersDependencies): DoomLoopLaunchersService {\n if (!generation || generation.length > MAX_GENERATION_LENGTH) {\n throw new TypeError('Doom loop launchers require a valid generation.');\n }\n\n const launchers = new Map<string, LauncherEntry>();\n const instances = new Map<string, InstanceEntry>();\n const listeners = new Set<() => void>();\n let registrationSequence = 0;\n let disposed = false;\n\n const ensureActive = (): void => {\n if (disposed) throw new Error('The Doom loop-launchers service is disposed.');\n };\n const notify = (): void => {\n for (const listener of listeners) listener();\n };\n const stopEntry = async (entry: InstanceEntry, reason?: string): Promise<void> => {\n if (instances.get(entry.instanceId) !== entry) return;\n entry.state = 'stopping';\n entry.abortController.abort(reason);\n notify();\n try {\n await entry.handle?.stop(reason);\n } finally {\n if (instances.get(entry.instanceId) === entry) instances.delete(entry.instanceId);\n notify();\n }\n };\n\n const service: DoomLoopLaunchersService = {\n generation,\n register(definition): LoopLauncherRegistration {\n ensureActive();\n const id = validId(definition.id, LAUNCHER_ID_LABEL);\n if (launchers.has(id)) throw new Error(`Loop launcher '${id}' is already registered.`);\n const token = Symbol(id);\n const entry: LauncherEntry = { token, definition: { ...definition, id } };\n launchers.set(id, entry);\n registrationSequence += 1;\n notify();\n let registrationDisposed = false;\n return Object.freeze({\n id,\n generation: `${generation}:launcher:${registrationSequence}`,\n async dispose(reason = 'Loop launcher disposed.'): Promise<void> {\n if (registrationDisposed) return;\n registrationDisposed = true;\n if (launchers.get(id)?.token !== token) return;\n launchers.delete(id);\n const owned = [...instances.values()].filter((instance) => instance.launcher.token === token);\n await Promise.allSettled(owned.map((instance) => stopEntry(instance, reason)));\n notify();\n },\n });\n },\n listLaunchers() {\n ensureActive();\n return [...launchers.values()]\n .map(({ definition }) => ({\n id: definition.id,\n source: definition.source,\n label: definition.label,\n ...(definition.description ? { description: definition.description } : {}),\n ...(definition.inputSchema ? { inputSchema: definition.inputSchema } : {}),\n }))\n .sort((left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id));\n },\n listInstances() {\n ensureActive();\n return [...instances.values()]\n .map(snapshot)\n .sort((left, right) => left.instanceId.localeCompare(right.instanceId));\n },\n subscribe(listener) {\n ensureActive();\n listeners.add(listener);\n let subscribed = true;\n return () => {\n if (!subscribed) return;\n subscribed = false;\n listeners.delete(listener);\n };\n },\n async launch(launcherId, options) {\n ensureActive();\n options?.signal?.throwIfAborted();\n const normalizedLauncherId = validId(launcherId, LAUNCHER_ID_LABEL);\n const launcher = launchers.get(normalizedLauncherId);\n if (!launcher) throw new Error(`Loop launcher '${normalizedLauncherId}' is unavailable.`);\n const instanceId = validId(options?.instanceId ?? createInstanceId(), INSTANCE_ID_LABEL);\n if (instances.has(instanceId)) throw new Error(`Loop instance '${instanceId}' already exists.`);\n const entry: InstanceEntry = { instanceId, launcher, abortController: new AbortController(), state: 'starting' };\n const abortSetup = (): void => entry.abortController.abort(options?.signal?.reason);\n options?.signal?.addEventListener('abort', abortSetup, { once: true });\n instances.set(instanceId, entry);\n notify();\n try {\n if (options?.interactive === false && !launcher.definition.inputSchema) {\n throw new Error(`Loop launcher '${normalizedLauncherId}' requires manual setup in Activity.`);\n }\n const handle = await launcher.definition.launch({\n instanceId,\n signal: entry.abortController.signal,\n ...(options?.input === undefined ? {} : { input: options.input }),\n ...(options?.interactive === undefined ? {} : { interactive: options.interactive }),\n });\n const active = !disposed && instances.get(instanceId) === entry && !entry.abortController.signal.aborted;\n if (!handle) {\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n return undefined;\n }\n if (!active || handle.instanceId !== instanceId) {\n await handle.stop(active ? 'Loop launcher returned a mismatched instance id.' : 'Loop launch was cancelled.');\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n if (active) throw new Error(`Loop launcher '${normalizedLauncherId}' returned a mismatched instance id.`);\n return undefined;\n }\n entry.handle = handle;\n entry.state = 'running';\n entry.startedAt = timestamp();\n notify();\n return snapshot(entry);\n } catch (error) {\n const cancelled = entry.abortController.signal.aborted || disposed;\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n if (cancelled) return undefined;\n throw error;\n } finally {\n options?.signal?.removeEventListener('abort', abortSetup);\n }\n },\n async stop(instanceId, reason) {\n ensureActive();\n const entry = instances.get(validId(instanceId, INSTANCE_ID_LABEL));\n if (!entry) return false;\n await stopEntry(entry, reason);\n return true;\n },\n async stopAll(reason) {\n if (disposed && instances.size === 0) return;\n await Promise.allSettled([...instances.values()].map((entry) => stopEntry(entry, reason)));\n },\n async dispose(reason = 'Doom loop-launchers service disposed.') {\n if (disposed) return;\n disposed = true;\n launchers.clear();\n await Promise.allSettled([...instances.values()].map((entry) => stopEntry(entry, reason)));\n listeners.clear();\n },\n };\n\n return Object.freeze(service);\n}\n","import { defineTool, type DoomPluginTool, type DoomPluginToolResult } from '@agimon-ai/doompi-core/piExtension';\nimport { Check } from 'typebox/value';\n\nimport type { DoomLoopLaunchersService } from '../../schemas/loopLaunchers';\nimport { LoopListSchema, LoopStartSchema, LoopStopSchema } from '../../schemas/loopTools';\n\nfunction result(details: unknown): DoomPluginToolResult {\n return { content: [{ type: 'text', text: JSON.stringify(details, null, 2) }], details };\n}\n\nexport function createLoopTools(\n launchers: () => DoomLoopLaunchersService,\n assertEnabled: () => void,\n): readonly DoomPluginTool[] {\n return [\n defineTool({\n name: 'loop_list',\n label: 'List loops',\n description: 'List active session loops and available launcher types with their configuration schemas.',\n parameters: LoopListSchema,\n async execute(input, { signal }) {\n assertEnabled();\n signal?.throwIfAborted();\n if (!Check(LoopListSchema, input)) throw new Error('loop_list takes no arguments.');\n const service = launchers();\n return result({ launchers: service.listLaunchers(), instances: service.listInstances() });\n },\n }),\n defineTool({\n name: 'loop_start',\n label: 'Start loop',\n description:\n 'Start a session-scoped loop without operator dialogs. Read loop_list for launcher IDs and input schemas. Loops stop when the session shuts down.',\n parameters: LoopStartSchema,\n executionMode: 'serial',\n async execute(input, { signal }) {\n assertEnabled();\n signal?.throwIfAborted();\n if (!Check(LoopStartSchema, input)) throw new Error('Provide launcherId, input, and optionally instanceId.');\n return result(\n (await launchers().launch(input.launcherId, { ...input, interactive: false, signal })) ?? { cancelled: true },\n );\n },\n }),\n defineTool({\n name: 'loop_stop',\n label: 'Stop loop',\n description:\n 'Stop one loop instance owned by the current session. Does not disable Loop mode or stop other loops.',\n parameters: LoopStopSchema,\n executionMode: 'serial',\n async execute(input, { signal }) {\n assertEnabled();\n signal?.throwIfAborted();\n if (!Check(LoopStopSchema, input)) throw new Error('Provide instanceId and an optional reason.');\n return result({ stopped: await launchers().stop(input.instanceId, input.reason ?? 'Stopped by the agent.') });\n },\n }),\n ];\n}\n","/** The browser-only status that carries active Loop instances into the activity dock. */\nexport const LOOP_VIEW_STATUS_KEY = 'doom-loop-instances';\n\nexport type LoopStatusState = 'starting' | 'running' | 'stopping';\n\n/** The small, serializable Loop view the cockpit needs for one activity row. */\nexport interface LoopStatusItem {\n readonly instanceId: string;\n readonly label: string;\n readonly detail: string;\n readonly state: LoopStatusState;\n}\n\ninterface LoopStatusSource {\n readonly instanceId: string;\n readonly launcherLabel: string;\n readonly label?: string;\n readonly detail?: string;\n readonly state: LoopStatusState;\n}\n\nconst ANSI = new RegExp(String.raw`\\u001b\\[[0-9;]*m`, 'gu');\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isState(value: unknown): value is LoopStatusState {\n return value === 'starting' || value === 'running' || value === 'stopping';\n}\n\n/** Projects runtime snapshots into the JSON status consumed by the web plugin. */\nexport function formatLoopStatusView(instances: readonly LoopStatusSource[]): string {\n if (instances.length === 0) return '';\n return JSON.stringify(\n instances.map((instance) => ({\n instanceId: instance.instanceId,\n label: instance.label ?? instance.launcherLabel,\n detail: instance.detail ?? instance.instanceId,\n state: instance.state,\n })),\n );\n}\n\n/** Reads a Loop status without letting malformed session data crash the activity dock. */\nexport function parseLoopStatusView(raw: string | undefined): LoopStatusItem[] | undefined {\n if (raw === undefined) return undefined;\n const text = raw.replace(ANSI, '').trim();\n if (text === '') return undefined;\n\n try {\n const value: unknown = JSON.parse(text);\n if (!Array.isArray(value) || value.length === 0) return undefined;\n const items: LoopStatusItem[] = [];\n for (const item of value) {\n if (\n !isRecord(item) ||\n typeof item.instanceId !== 'string' ||\n item.instanceId.trim() === '' ||\n typeof item.label !== 'string' ||\n item.label.trim() === '' ||\n typeof item.detail !== 'string' ||\n !isState(item.state)\n ) {\n return undefined;\n }\n items.push({ instanceId: item.instanceId, label: item.label, detail: item.detail, state: item.state });\n }\n return items;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;AAAA,MAAa,iBAAiB;AAE9B,MAAa,aAAa;AAC1B,MAAa,iBAAiB;AAC9B,MAAa,oBAAoB;AACjC,MAAa,oBAAoB;AACjC,MAAa,uBAAuB;;;ACNpC,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;;;ACAjC,MAAa,iBAAiBA,QAAAA,KAAK,OAAO,CAAC,GAAG,EAAE,sBAAsB,MAAM,CAAC;AAC7E,MAAa,kBAAkBA,QAAAA,KAAK,OAClC;CACE,YAAYA,QAAAA,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC;CACxD,YAAYA,QAAAA,KAAK,SAASA,QAAAA,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC,CAAC;CACvE,OAAOA,QAAAA,KAAK,OAAOA,QAAAA,KAAK,OAAO,GAAGA,QAAAA,KAAK,QAAQ,CAAC;AAClD,GACA,EAAE,sBAAsB,MAAM,CAChC;AACA,MAAa,iBAAiBA,QAAAA,KAAK,OACjC;CACE,YAAYA,QAAAA,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC;CACxD,QAAQA,QA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