@pasko70/pibo 1.9.13 → 1.10.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 (163) hide show
  1. package/README.md +183 -183
  2. package/context/codex-base-prompt.md +148 -148
  3. package/context/compute-worker.md +23 -23
  4. package/context/pibo-compaction-prompt.md +100 -100
  5. package/context/pibo-native-tooling.md +18 -18
  6. package/context/pibo-system-prompt.md +77 -77
  7. package/dist/apps/chat/agent-profiles.js +2 -2
  8. package/dist/apps/chat/agent-store.js +263 -250
  9. package/dist/apps/chat/chat-request-normalizers.js +17 -0
  10. package/dist/apps/chat/data/chat-data-mappers.js +2 -0
  11. package/dist/apps/chat/data/project-service.js +168 -168
  12. package/dist/apps/chat/data/read-state-service.js +18 -18
  13. package/dist/apps/chat/data/session-query-service.js +25 -25
  14. package/dist/apps/chat/data/timeline-query-service.js +19 -19
  15. package/dist/apps/chat/loop-api.js +181 -0
  16. package/dist/apps/chat/static-assets.js +854 -854
  17. package/dist/apps/chat/web-app.js +36 -16
  18. package/dist/apps/chat/workflow-manual-trigger-runtime.js +149 -46
  19. package/dist/apps/chat/workflow-persistence.js +255 -255
  20. package/dist/apps/chat-ui/assets/{dist-BZ2eTC4f.js → dist-3Sts0Afa.js} +1 -1
  21. package/dist/apps/chat-ui/assets/{dist-BHa-kcGl.js → dist-4NlLjLs7.js} +1 -1
  22. package/dist/apps/chat-ui/assets/{dist-yCYNNb5d.js → dist-BA6mhAec.js} +1 -1
  23. package/dist/apps/chat-ui/assets/{dist-D811wJeV.js → dist-BPl-fzRB.js} +1 -1
  24. package/dist/apps/chat-ui/assets/{dist-Dq4GxJi3.js → dist-BPnn9e2B.js} +1 -1
  25. package/dist/apps/chat-ui/assets/{dist-CzE6k3F3.js → dist-BpfBSMzK.js} +1 -1
  26. package/dist/apps/chat-ui/assets/{dist-CnVsqwSG.js → dist-Cvx5M97R.js} +1 -1
  27. package/dist/apps/chat-ui/assets/{dist-WyXdYl-w.js → dist-DnXWNQRm.js} +1 -1
  28. package/dist/apps/chat-ui/assets/{dist-BNMu92bb.js → dist-hU-2oAb6.js} +1 -1
  29. package/dist/apps/chat-ui/assets/{dist-BCB6zezO.js → dist-r31x5Fcc.js} +1 -1
  30. package/dist/apps/chat-ui/assets/{dist-HqTN67dc.js → dist-uF6UXzI7.js} +1 -1
  31. package/dist/apps/chat-ui/assets/index-CaTGYBOS.js +173 -0
  32. package/dist/apps/chat-ui/assets/{index-C0x9nEcf.css → index-al8DeEjA.css} +1 -1
  33. package/dist/apps/chat-ui/index.html +18 -18
  34. package/dist/apps/chat-ui/manifest.webmanifest +25 -25
  35. package/dist/apps/chat-ui/sw.js +47 -47
  36. package/dist/apps/chat-vscode-web/assets/index-CK4SMZuu.js +41 -0
  37. package/dist/apps/chat-vscode-web/index.html +13 -13
  38. package/dist/apps/cli-ui/cliSessionsCommand.js +23 -23
  39. package/dist/apps/context-files-ui/index.html +11 -11
  40. package/dist/cli-session/localSessionSource.js +34 -12
  41. package/dist/cli.js +61 -44
  42. package/dist/compute/cli.js +54 -54
  43. package/dist/compute/resource-health.js +35 -2
  44. package/dist/core/events.js +6 -1
  45. package/dist/core/routed-session.js +97 -5
  46. package/dist/core/runtime.js +6 -1
  47. package/dist/core/session-router.js +27 -8
  48. package/dist/cron/cli.js +15 -15
  49. package/dist/cron/store.js +49 -49
  50. package/dist/data/cli.js +23 -23
  51. package/dist/data/event-log.js +23 -23
  52. package/dist/data/ingest-service.js +3 -1
  53. package/dist/data/message-store.js +27 -27
  54. package/dist/data/navigation-store.js +9 -9
  55. package/dist/data/observation-store.js +4 -4
  56. package/dist/data/payload-store.js +17 -17
  57. package/dist/data/schema.js +433 -433
  58. package/dist/data/session-store.js +4 -4
  59. package/dist/data/telemetry-queries.js +54 -54
  60. package/dist/data/telemetry.js +197 -197
  61. package/dist/debug/events.js +12 -12
  62. package/dist/debug/failures.js +6 -6
  63. package/dist/debug/index.js +231 -227
  64. package/dist/debug/messages.js +6 -6
  65. package/dist/debug/pty.js +124 -124
  66. package/dist/debug/session.js +29 -29
  67. package/dist/debug/tools.js +5 -5
  68. package/dist/debug/trace.js +42 -7
  69. package/dist/debug/web-snapshot-browser-scripts.js +294 -294
  70. package/dist/debug/web-streaming-browser-library.js +925 -925
  71. package/dist/debug/web-streaming-browser-scripts.js +232 -232
  72. package/dist/debug/web-streaming-provider-telemetry.js +4 -4
  73. package/dist/debug/web.js +93 -93
  74. package/dist/gateway/cli.js +19 -19
  75. package/dist/gateway/server.js +4 -2
  76. package/dist/gateway/web.js +2 -2
  77. package/dist/index.js +1 -0
  78. package/dist/loops/accounting.js +19 -0
  79. package/dist/loops/channel.js +8 -0
  80. package/dist/loops/cli.js +224 -0
  81. package/dist/loops/plugin.js +16 -0
  82. package/dist/loops/prompts.js +86 -0
  83. package/dist/loops/service.js +446 -0
  84. package/dist/loops/stopping.js +170 -0
  85. package/dist/loops/store.js +642 -0
  86. package/dist/loops/templates.js +232 -0
  87. package/dist/loops/tools.js +184 -0
  88. package/dist/loops/types.js +1 -0
  89. package/dist/mcp/config-command.js +53 -53
  90. package/dist/mcp/index.js +21 -21
  91. package/dist/mcp/registry.js +11 -11
  92. package/dist/pi-packages/cli.js +11 -11
  93. package/dist/plugins/builtin.js +8 -0
  94. package/dist/plugins/context-files-store.js +110 -110
  95. package/dist/plugins/context-files.js +4 -4
  96. package/dist/plugins/registry.js +23 -12
  97. package/dist/ralph/cli.js +18 -18
  98. package/dist/ralph/templates.js +140 -140
  99. package/dist/reliability/store.js +256 -229
  100. package/dist/runs/lifecycle.js +59 -0
  101. package/dist/runs/registry.js +47 -1
  102. package/dist/runs/tools.js +31 -13
  103. package/dist/session-ui/terminalRows.js +66 -2
  104. package/dist/sessions/pibo-data-store.js +16 -16
  105. package/dist/sessions/sqlite-store.js +53 -53
  106. package/dist/setup/cli.js +58 -58
  107. package/dist/shared/trace-async-agent-runs.js +4 -4
  108. package/dist/shared/trace-event-projection.js +59 -19
  109. package/dist/shared/trace-nodes.js +5 -0
  110. package/dist/shared/trace-page-merge.js +15 -0
  111. package/dist/shared/trace-run-notifications.js +3 -1
  112. package/dist/signals/projector.js +6 -2
  113. package/dist/tools/agent-browser-wrapper.js +80 -80
  114. package/dist/tools/browser-pool.js +50 -0
  115. package/dist/tools/browser-use-cdp.js +12 -12
  116. package/dist/tools/browser-use-leases.js +12 -8
  117. package/dist/tools/browser-use-wrapper.js +762 -762
  118. package/dist/tools/guides.js +596 -538
  119. package/dist/tools/index.js +123 -99
  120. package/dist/tools/registry.js +21 -3
  121. package/dist/tools/runtime/node-worker-source.js +205 -205
  122. package/dist/tools/runtime/python-worker-source.js +177 -177
  123. package/dist/vscode/cli.js +9 -9
  124. package/dist/web-annotations/cdp.js +900 -900
  125. package/dist/web-annotations/store.js +96 -96
  126. package/docs/README.md +23 -23
  127. package/docs/ops/install-developer-host.md +112 -112
  128. package/docs/ops/install-user-host.md +96 -96
  129. package/docs/ops/upgrade-user-to-developer-host.md +69 -69
  130. package/docs/ops/vscode-extension-release.md +160 -160
  131. package/package.json +99 -95
  132. package/skills/builtin/graphify/SKILL.md +52 -52
  133. package/skills/builtin/loop/SKILL.md +78 -0
  134. package/skills/builtin/pi-agent-harness/SKILL.md +319 -319
  135. package/skills/builtin/pi-agent-harness/agents/openai.yaml +4 -4
  136. package/skills/builtin/pibo-docker-system/SKILL.md +170 -170
  137. package/skills/builtin/pibo-spec-writing/SKILL.md +330 -330
  138. package/skills/builtin/prd/SKILL.md +143 -143
  139. package/skills/builtin/ralph-loop/SKILL.md +361 -359
  140. package/skills/builtin/ralph-prd-json/SKILL.md +123 -123
  141. package/skills/builtin/skill-creator/LICENSE.txt +201 -201
  142. package/skills/builtin/skill-creator/SKILL.md +513 -513
  143. package/skills/builtin/skill-creator/agents/analyzer.md +274 -274
  144. package/skills/builtin/skill-creator/agents/comparator.md +202 -202
  145. package/skills/builtin/skill-creator/agents/grader.md +223 -223
  146. package/skills/builtin/skill-creator/assets/eval_review.html +146 -146
  147. package/skills/builtin/skill-creator/eval-viewer/generate_review.py +471 -471
  148. package/skills/builtin/skill-creator/eval-viewer/viewer.html +1325 -1325
  149. package/skills/builtin/skill-creator/references/schemas.md +430 -430
  150. package/skills/builtin/skill-creator/scripts/aggregate_benchmark.py +401 -401
  151. package/skills/builtin/skill-creator/scripts/generate_report.py +326 -326
  152. package/skills/builtin/skill-creator/scripts/improve_description.py +247 -247
  153. package/skills/builtin/skill-creator/scripts/package_skill.py +136 -136
  154. package/skills/builtin/skill-creator/scripts/quick_validate.py +102 -102
  155. package/skills/builtin/skill-creator/scripts/run_eval.py +310 -310
  156. package/skills/builtin/skill-creator/scripts/run_loop.py +328 -328
  157. package/skills/builtin/skill-creator/scripts/utils.py +47 -47
  158. package/skills/builtin/web-annotations/SKILL.md +93 -93
  159. package/src/mcp/LICENSE.mcp-cli +21 -21
  160. package/dist/apps/chat-ui/assets/index-DwHJfmiF.js +0 -173
  161. package/dist/apps/chat-vscode-web/assets/index-BAMxIaI_.js +0 -41
  162. package/dist/apps/vscode-artifacts/latest.vsix +0 -0
  163. package/dist/apps/vscode-artifacts/pibo-vscode-ext-1.9.13.vsix +0 -0
@@ -0,0 +1,181 @@
1
+ import { PiboWebHttpError, readJsonBody, responseJson } from '../../web/http.js';
2
+ import { getPiboLoopService } from '../../loops/channel.js';
3
+ import { listLoopJobTemplates } from '../../loops/templates.js';
4
+ import { isPiboThinkingLevel } from '../../core/thinking.js';
5
+ import { normalizeLoopStopPolicy } from '../../loops/store.js';
6
+ import { isPiboRoomArchived } from './types/rooms.js';
7
+ const CHAT_WEB_API_PREFIX = '/api/chat';
8
+ function requireSameOriginJsonRequest(request) { const contentType = request.headers.get('content-type')?.split(';')[0]?.trim().toLowerCase(); if (contentType !== 'application/json')
9
+ throw new PiboWebHttpError('Content-Type must be application/json', 415); const origin = request.headers.get('origin'); if (!origin)
10
+ throw new PiboWebHttpError('Origin header is required', 403); if (origin !== new URL(request.url).origin)
11
+ throw new PiboWebHttpError('Origin is not allowed', 403); }
12
+ function accessDenied(error) { throw new PiboWebHttpError(error instanceof Error ? error.message : 'Access denied', 403); }
13
+ function normalizeString(value, field, options = {}) { if (value === undefined || value === null) {
14
+ if (options.required)
15
+ throw new PiboWebHttpError(`${field} is required`, 400);
16
+ return undefined;
17
+ } if (typeof value !== 'string')
18
+ throw new PiboWebHttpError(`${field} must be a string`, 400); const normalized = value.trim(); if (!normalized && options.required)
19
+ throw new PiboWebHttpError(`${field} is required`, 400); if (options.max && normalized.length > options.max)
20
+ throw new PiboWebHttpError(`${field} is too long`, 400); return normalized || undefined; }
21
+ function normalizeEnabled(value) { if (value === undefined)
22
+ return undefined; if (typeof value !== 'boolean')
23
+ throw new PiboWebHttpError('enabled must be a boolean', 400); return value; }
24
+ function normalizeMode(value, fallback) { if (value === undefined || value === null || value === '')
25
+ return fallback; if (value !== 'goal' && value !== 'ralph')
26
+ throw new PiboWebHttpError('mode must be goal or ralph', 400); return value; }
27
+ function normalizeMaxIterations(value) { if (value === undefined || value === null || value === '')
28
+ return undefined; if (typeof value !== 'number' || !Number.isInteger(value) || value < 1)
29
+ throw new PiboWebHttpError('maxIterations must be a positive integer', 400); return value; }
30
+ function normalizeTokenBudget(value) { if (value === undefined || value === null || value === '')
31
+ return undefined; if (typeof value !== 'number' || !Number.isInteger(value) || value < 1)
32
+ throw new PiboWebHttpError('tokenBudget must be a positive integer', 400); return value; }
33
+ function normalizeTokenReserve(value) { if (value === undefined || value === null || value === '')
34
+ return undefined; if (typeof value !== 'number' || !Number.isInteger(value) || value < 0)
35
+ throw new PiboWebHttpError('tokenReserve must be a non-negative integer', 400); return value; }
36
+ function normalizeStopPolicy(value) { if (value === undefined || value === null)
37
+ return undefined; try {
38
+ return normalizeLoopStopPolicy(value);
39
+ }
40
+ catch (error) {
41
+ throw new PiboWebHttpError(error instanceof Error ? error.message : 'Invalid stopPolicy', 400);
42
+ } }
43
+ function normalizeModelOverride(value) { if (value === undefined || value === null)
44
+ return undefined; if (!value || typeof value !== 'object' || Array.isArray(value))
45
+ throw new PiboWebHttpError('modelOverride must be an object', 400); const raw = value; if (typeof raw.provider !== 'string' || typeof raw.id !== 'string')
46
+ throw new PiboWebHttpError('modelOverride must include provider and id', 400); const provider = raw.provider.trim(); const id = raw.id.trim(); if (!provider || !id)
47
+ throw new PiboWebHttpError('modelOverride must include provider and id', 400); return { provider, id }; }
48
+ function normalizeThinkingLevel(value) { if (value === undefined || value === null || value === '')
49
+ return undefined; if (typeof value !== 'string' || !isPiboThinkingLevel(value))
50
+ throw new PiboWebHttpError('thinkingLevel must be one of off, minimal, low, medium, high, xhigh, max', 400); return value; }
51
+ function normalizeFastMode(value) { if (value === undefined || value === null)
52
+ return undefined; if (typeof value !== 'boolean')
53
+ throw new PiboWebHttpError('fastMode must be a boolean', 400); return value; }
54
+ function normalizeTarget(value, options) { if (!value || typeof value !== 'object' || Array.isArray(value))
55
+ throw new PiboWebHttpError('target is required', 400); const raw = value; if (raw.kind === 'room') {
56
+ const roomId = normalizeString(raw.roomId, 'target.roomId', { required: true });
57
+ let room;
58
+ try {
59
+ room = options.roomService.requireRoom(roomId);
60
+ }
61
+ catch (error) {
62
+ accessDenied(error);
63
+ }
64
+ if (isPiboRoomArchived(room))
65
+ throw new PiboWebHttpError('Archived rooms are read-only', 403);
66
+ return { kind: 'room', roomId };
67
+ } if (raw.kind === 'default-chat') {
68
+ options.roomService.ensureDefaultRoom({ name: 'Shared Chat' });
69
+ return { kind: 'default-chat' };
70
+ } throw new PiboWebHttpError('target.kind must be room or default-chat', 400); }
71
+ function resolveProfile(context, fallback, value) { const requested = normalizeString(value, 'profile') ?? fallback; const profile = context.channelContext.getProfiles?.().find((item) => item.name === requested || item.aliases.includes(requested)); if (!profile)
72
+ throw new PiboWebHttpError(`Unknown profile: ${requested}`, 400); return profile.name; }
73
+ function jobResource(pathname) { const prefix = `${CHAT_WEB_API_PREFIX}/loops/jobs/`; if (!pathname.startsWith(prefix))
74
+ return undefined; const parts = pathname.slice(prefix.length).split('/').filter(Boolean).map((part) => decodeURIComponent(part)); if (!parts[0] || parts.length > 2)
75
+ return undefined; if (parts[1] && !['start', 'stop', 'cancel'].includes(parts[1]))
76
+ return undefined; return { id: parts[0], child: parts[1] }; }
77
+ function createPatch(body, options) { const patch = {}; if (body.mode !== undefined)
78
+ patch.mode = normalizeMode(body.mode, 'goal'); const name = normalizeString(body.name, 'name', { max: 120 }); if (body.name !== undefined && name !== undefined)
79
+ patch.name = name; if (body.description !== undefined)
80
+ patch.description = normalizeString(body.description, 'description', { max: 500 }); const enabled = normalizeEnabled(body.enabled); if (enabled !== undefined)
81
+ patch.enabled = enabled; if (body.target !== undefined)
82
+ patch.target = normalizeTarget(body.target, options); if (body.profile !== undefined)
83
+ patch.profile = resolveProfile(options.context, options.defaultProfile, body.profile); if (body.prompt !== undefined)
84
+ patch.prompt = normalizeString(body.prompt, 'prompt', { required: true, max: 20_000 }); if (body.maxIterations !== undefined)
85
+ patch.maxIterations = normalizeMaxIterations(body.maxIterations) ?? null; if (body.tokenBudget !== undefined)
86
+ patch.tokenBudget = normalizeTokenBudget(body.tokenBudget) ?? null; if (body.tokenReserve !== undefined)
87
+ patch.tokenReserve = normalizeTokenReserve(body.tokenReserve) ?? null; if (body.stopPolicy !== undefined)
88
+ patch.stopPolicy = normalizeStopPolicy(body.stopPolicy) ?? null; if (body.modelOverride !== undefined)
89
+ patch.modelOverride = normalizeModelOverride(body.modelOverride) ?? null; if (body.thinkingLevel !== undefined)
90
+ patch.thinkingLevel = normalizeThinkingLevel(body.thinkingLevel) ?? null; if (body.fastMode !== undefined)
91
+ patch.fastMode = normalizeFastMode(body.fastMode) ?? null; if (Object.keys(patch).length === 0)
92
+ throw new PiboWebHttpError('No Loop job update fields provided', 400); return patch; }
93
+ function serializeTarget(target) { return target.kind === 'room' ? target : { kind: 'default-chat' }; }
94
+ function serializeJob(job) { const { target, ...rest } = job; return { ...rest, target: serializeTarget(target) }; }
95
+ function serializeRun(run) { return run; }
96
+ export async function handleChatLoopApiRequest(options) {
97
+ const { request, loopStore } = options;
98
+ const url = new URL(request.url);
99
+ const legacyRalphRequest = url.pathname.startsWith(`${CHAT_WEB_API_PREFIX}/ralph`);
100
+ if (!legacyRalphRequest && !url.pathname.startsWith(`${CHAT_WEB_API_PREFIX}/loops`) && !url.pathname.startsWith(`${CHAT_WEB_API_PREFIX}/loop`))
101
+ return undefined;
102
+ const apiPath = url.pathname.replace(/^\/api\/chat\/(?:ralph|loop)(?=\/|$)/, `${CHAT_WEB_API_PREFIX}/loops`);
103
+ if (apiPath === `${CHAT_WEB_API_PREFIX}/loops/status` && request.method === 'GET')
104
+ return responseJson({ status: getPiboLoopService()?.status() ?? { enabled: false, ...loopStore.status() } });
105
+ if (apiPath === `${CHAT_WEB_API_PREFIX}/loops/conditions` && request.method === 'GET')
106
+ return responseJson({ conditions: options.context.channelContext.getLoopStopConditionInfos?.() ?? options.context.channelContext.getCapabilityCatalog?.().loopStopConditions ?? [] });
107
+ if (apiPath === `${CHAT_WEB_API_PREFIX}/loops/templates` && request.method === 'GET')
108
+ return responseJson({ templates: listLoopJobTemplates() });
109
+ if (apiPath === `${CHAT_WEB_API_PREFIX}/loops/jobs` && request.method === 'GET')
110
+ return responseJson({ jobs: loopStore.listJobs({ includeDisabled: url.searchParams.get('includeDisabled') === 'true' }).map(serializeJob) });
111
+ if (apiPath === `${CHAT_WEB_API_PREFIX}/loops/jobs` && request.method === 'POST') {
112
+ requireSameOriginJsonRequest(request);
113
+ const body = await readJsonBody(request);
114
+ const mode = normalizeMode(body.mode, legacyRalphRequest ? 'ralph' : 'goal');
115
+ const tokenBudget = normalizeTokenBudget(body.tokenBudget);
116
+ const tokenReserve = normalizeTokenReserve(body.tokenReserve);
117
+ if (mode === 'ralph' && (tokenBudget !== undefined || tokenReserve !== undefined))
118
+ throw new PiboWebHttpError('tokenBudget and tokenReserve are only available for goal mode', 400);
119
+ const job = loopStore.createJob({ mode, name: normalizeString(body.name, 'name', { max: 120 }), description: normalizeString(body.description, 'description', { max: 500 }), enabled: normalizeEnabled(body.enabled), target: normalizeTarget(body.target, options), profile: resolveProfile(options.context, options.defaultProfile, body.profile), prompt: normalizeString(body.prompt, 'prompt', { required: true, max: 20_000 }), maxIterations: normalizeMaxIterations(body.maxIterations), tokenBudget, tokenReserve, stopPolicy: normalizeStopPolicy(body.stopPolicy), modelOverride: normalizeModelOverride(body.modelOverride), thinkingLevel: normalizeThinkingLevel(body.thinkingLevel), fastMode: normalizeFastMode(body.fastMode) });
120
+ return responseJson({ job: serializeJob(job) }, { status: 201 });
121
+ }
122
+ if (apiPath === `${CHAT_WEB_API_PREFIX}/loops/runs` && request.method === 'GET') {
123
+ const jobId = url.searchParams.get('jobId') || undefined;
124
+ const limit = Number(url.searchParams.get('limit') ?? '100');
125
+ if (jobId && !loopStore.getJob(jobId))
126
+ throw new PiboWebHttpError('Loop job not found', 404);
127
+ return responseJson({ runs: loopStore.listRuns({ jobId, limit: Number.isFinite(limit) ? limit : 100 }).map(serializeRun) });
128
+ }
129
+ const resource = jobResource(apiPath);
130
+ if (!resource)
131
+ return undefined;
132
+ if (resource.child && request.method === 'POST') {
133
+ requireSameOriginJsonRequest(request);
134
+ const service = getPiboLoopService();
135
+ if (!service)
136
+ throw new PiboWebHttpError('Loop service is not running', 503);
137
+ if (resource.child === 'start') {
138
+ const run = await service.startJob(resource.id);
139
+ if (!run)
140
+ throw new PiboWebHttpError('Loop job not found, already running, or stopped by a before-run condition', 404);
141
+ return responseJson({ run: serializeRun(run) }, { status: 202 });
142
+ }
143
+ if (resource.child === 'stop') {
144
+ const job = service.stopJob(resource.id);
145
+ if (!job)
146
+ throw new PiboWebHttpError('Loop job not found', 404);
147
+ return responseJson({ job: serializeJob(job) });
148
+ }
149
+ const job = await service.cancelJob(resource.id);
150
+ if (!job)
151
+ throw new PiboWebHttpError('Loop job not found', 404);
152
+ return responseJson({ job: serializeJob(job) });
153
+ }
154
+ if (resource.child)
155
+ return undefined;
156
+ if (request.method === 'GET') {
157
+ const job = loopStore.getJob(resource.id);
158
+ if (!job)
159
+ throw new PiboWebHttpError('Loop job not found', 404);
160
+ return responseJson({ job: serializeJob(job) });
161
+ }
162
+ if (request.method === 'PATCH') {
163
+ requireSameOriginJsonRequest(request);
164
+ const body = await readJsonBody(request);
165
+ const patch = createPatch(body, options);
166
+ const existing = loopStore.getJob(resource.id);
167
+ if (!existing)
168
+ throw new PiboWebHttpError('Loop job not found', 404);
169
+ if ((patch.mode ?? existing.mode) === 'ralph' && ((patch.tokenBudget !== undefined && patch.tokenBudget !== null) || (patch.tokenReserve !== undefined && patch.tokenReserve !== null)))
170
+ throw new PiboWebHttpError('tokenBudget and tokenReserve are only available for goal mode', 400);
171
+ const job = loopStore.updateJob(resource.id, patch);
172
+ if (!job)
173
+ throw new PiboWebHttpError('Loop job not found', 404);
174
+ return responseJson({ job: serializeJob(job) });
175
+ }
176
+ if (request.method === 'DELETE') {
177
+ requireSameOriginJsonRequest(request);
178
+ return responseJson({ removed: loopStore.removeJob(resource.id) });
179
+ }
180
+ return undefined;
181
+ }