@cursor/july 0.1.5 → 0.1.7

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 (177) hide show
  1. package/dist/ab.d.ts +8 -95
  2. package/dist/ab.d.ts.map +1 -1
  3. package/dist/ab.js +9 -150
  4. package/dist/bin/agent-serve.js +41 -8
  5. package/dist/channels/slack/post-update-delivery.d.ts +85 -0
  6. package/dist/channels/slack/post-update-delivery.d.ts.map +1 -0
  7. package/dist/docs/404.html +2 -2
  8. package/dist/docs/ab.html +4 -4
  9. package/dist/docs/assets/{app.DabPG-io.js → app.COTN7wgo.js} +1 -1
  10. package/dist/docs/assets/chunks/@localSearchIndexroot.B7UcKvIn.js +1 -0
  11. package/dist/docs/assets/chunks/{VPLocalSearchBox.jmyr0bU0.js → VPLocalSearchBox.BW3TBdT0.js} +1 -1
  12. package/dist/docs/assets/chunks/{theme.DysN9-VN.js → theme.BEJW0vE7.js} +2 -2
  13. package/dist/docs/assets/deployment.md.BtfEsc9S.js +55 -0
  14. package/dist/docs/assets/deployment.md.BtfEsc9S.lean.js +1 -0
  15. package/dist/docs/assets/example-agents_approval-buddy.md.8R5phXb5.js +10 -0
  16. package/dist/docs/assets/example-agents_approval-buddy.md.8R5phXb5.lean.js +1 -0
  17. package/dist/docs/assets/example-agents_benny.md.B0gjhI-p.js +7 -0
  18. package/dist/docs/assets/example-agents_benny.md.B0gjhI-p.lean.js +1 -0
  19. package/dist/docs/assets/example-agents_bugbot.md.DelIdhxB.js +11 -0
  20. package/dist/docs/assets/example-agents_bugbot.md.DelIdhxB.lean.js +1 -0
  21. package/dist/docs/assets/example-agents_codebase-wiki.md.DC6sgwn0.js +8 -0
  22. package/dist/docs/assets/example-agents_codebase-wiki.md.DC6sgwn0.lean.js +1 -0
  23. package/dist/docs/assets/example-agents_codeowners-review.md.Ku_tG2RY.js +8 -0
  24. package/dist/docs/assets/example-agents_codeowners-review.md.Ku_tG2RY.lean.js +1 -0
  25. package/dist/docs/assets/example-agents_concierge.md.4rQTSMXt.js +23 -0
  26. package/dist/docs/assets/example-agents_concierge.md.4rQTSMXt.lean.js +1 -0
  27. package/dist/docs/assets/example-agents_fsd.md.CzgUrDfi.js +15 -0
  28. package/dist/docs/assets/example-agents_fsd.md.CzgUrDfi.lean.js +1 -0
  29. package/dist/docs/assets/example-agents_index.md.CRqJlnIf.js +2 -0
  30. package/dist/docs/assets/example-agents_index.md.CRqJlnIf.lean.js +1 -0
  31. package/dist/docs/assets/example-agents_knowledge-base.md.BPJiVueF.js +11 -0
  32. package/dist/docs/assets/example-agents_knowledge-base.md.BPJiVueF.lean.js +1 -0
  33. package/dist/docs/assets/example-agents_security-reviewer.md.D2rtwDTO.js +19 -0
  34. package/dist/docs/assets/example-agents_security-reviewer.md.D2rtwDTO.lean.js +1 -0
  35. package/dist/docs/assets/example-agents_slack-agent.md.buLbgvBf.js +5 -0
  36. package/dist/docs/assets/example-agents_slack-agent.md.buLbgvBf.lean.js +1 -0
  37. package/dist/docs/assets/example-agents_weather-agent.md.C9Qv-W0o.js +24 -0
  38. package/dist/docs/assets/example-agents_weather-agent.md.C9Qv-W0o.lean.js +1 -0
  39. package/dist/docs/assets/index.md.COiu-1jL.js +20 -0
  40. package/dist/docs/assets/{index.md.Cylk70gg.lean.js → index.md.COiu-1jL.lean.js} +1 -1
  41. package/dist/docs/assets/reference_cli.md.D189RBCH.js +60 -0
  42. package/dist/docs/assets/reference_cli.md.D189RBCH.lean.js +1 -0
  43. package/dist/docs/building-with-agents.html +4 -4
  44. package/dist/docs/concepts.html +4 -4
  45. package/dist/docs/deployment.html +58 -17
  46. package/dist/docs/evals.html +4 -4
  47. package/dist/docs/example-agents/approval-buddy.html +34 -0
  48. package/dist/docs/example-agents/benny.html +31 -0
  49. package/dist/docs/example-agents/bugbot.html +35 -0
  50. package/dist/docs/example-agents/codebase-wiki.html +32 -0
  51. package/dist/docs/example-agents/codeowners-review.html +32 -0
  52. package/dist/docs/example-agents/concierge.html +47 -0
  53. package/dist/docs/example-agents/fsd.html +39 -0
  54. package/dist/docs/example-agents/index.html +26 -0
  55. package/dist/docs/example-agents/knowledge-base.html +35 -0
  56. package/dist/docs/example-agents/security-reviewer.html +43 -0
  57. package/dist/docs/example-agents/slack-agent.html +29 -0
  58. package/dist/docs/example-agents/weather-agent.html +48 -0
  59. package/dist/docs/guides/agent-to-agent.html +4 -4
  60. package/dist/docs/guides/cloud-runtime.html +5 -5
  61. package/dist/docs/guides/github.html +4 -4
  62. package/dist/docs/guides/human-in-the-loop.html +4 -4
  63. package/dist/docs/guides/slack.html +4 -4
  64. package/dist/docs/guides/webhooks.html +4 -4
  65. package/dist/docs/hashmap.json +1 -1
  66. package/dist/docs/hillclimbing.html +4 -4
  67. package/dist/docs/index.html +7 -7
  68. package/dist/docs/quickstart.html +4 -4
  69. package/dist/docs/reference/agent-config.html +4 -4
  70. package/dist/docs/reference/channels.html +4 -4
  71. package/dist/docs/reference/cli.html +52 -30
  72. package/dist/docs/reference/connections.html +4 -4
  73. package/dist/docs/reference/hooks.html +4 -4
  74. package/dist/docs/reference/http-api.html +4 -4
  75. package/dist/docs/reference/instructions.html +4 -4
  76. package/dist/docs/reference/playground.html +4 -4
  77. package/dist/docs/reference/project-layout.html +4 -4
  78. package/dist/docs/reference/schedules.html +4 -4
  79. package/dist/docs/reference/sessions.html +4 -4
  80. package/dist/docs/reference/skills.html +4 -4
  81. package/dist/docs/reference/subagents.html +4 -4
  82. package/dist/docs/reference/tools.html +4 -4
  83. package/dist/docs/scaffolding-agents.html +4 -4
  84. package/dist/docs/storage.html +4 -4
  85. package/dist/docs/troubleshooting.html +4 -4
  86. package/dist/evals.d.ts +5 -62
  87. package/dist/evals.d.ts.map +1 -1
  88. package/dist/evals.js +3 -66
  89. package/dist/index.d.ts +1 -1
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/internal/ab-collector.d.ts +7 -5
  92. package/dist/internal/ab-collector.d.ts.map +1 -1
  93. package/dist/internal/ab-collector.js +3 -14
  94. package/dist/internal/ab-snapshot.d.ts +2 -4
  95. package/dist/internal/ab-snapshot.d.ts.map +1 -1
  96. package/dist/internal/cli-ax.d.ts +33 -5
  97. package/dist/internal/cli-ax.d.ts.map +1 -1
  98. package/dist/internal/cli-ax.js +428 -87
  99. package/dist/internal/cli-deploy.js +1 -1
  100. package/dist/internal/discovery.js +3 -3
  101. package/dist/internal/eval-run-store.d.ts +35 -30
  102. package/dist/internal/eval-run-store.d.ts.map +1 -1
  103. package/dist/internal/eval-run-store.js +88 -100
  104. package/dist/internal/evals-client.d.ts +96 -0
  105. package/dist/internal/evals-client.d.ts.map +1 -0
  106. package/dist/internal/evals-client.js +262 -0
  107. package/dist/internal/init-project.d.ts.map +1 -1
  108. package/dist/internal/init-project.js +1 -0
  109. package/dist/internal/persistence-coordinator.d.ts +127 -0
  110. package/dist/internal/persistence-coordinator.d.ts.map +1 -0
  111. package/dist/internal/playground-proxy.d.ts +5 -5
  112. package/dist/internal/playground-proxy.js +3 -3
  113. package/dist/internal/resolve-prod-target.d.ts +30 -0
  114. package/dist/internal/resolve-prod-target.d.ts.map +1 -1
  115. package/dist/internal/resolve-prod-target.js +74 -2
  116. package/dist/internal/server.d.ts.map +1 -1
  117. package/dist/internal/server.js +16 -5
  118. package/dist/internal/session-engine.d.ts +1 -2
  119. package/dist/internal/session-engine.d.ts.map +1 -1
  120. package/dist/internal/session-engine.js +14 -31
  121. package/dist/internal/storage-coordinator.d.ts +16 -15
  122. package/dist/internal/storage-coordinator.d.ts.map +1 -1
  123. package/dist/internal/storage-coordinator.js +73 -80
  124. package/dist/persistence.d.ts +184 -0
  125. package/dist/persistence.d.ts.map +1 -0
  126. package/dist/playground/assets/cursor-icons-16-CQ50JpfO.woff2 +0 -0
  127. package/dist/playground/assets/index-72vCOBWO.js +86 -0
  128. package/dist/playground/assets/index-BjnMwYoR.css +1 -0
  129. package/dist/playground/index.html +2 -2
  130. package/dist/storage.d.ts +51 -10
  131. package/dist/storage.d.ts.map +1 -1
  132. package/dist/storage.js +27 -10
  133. package/docs/README.md +34 -5
  134. package/docs/deployment.md +352 -149
  135. package/docs/example-agents/approval-buddy.md +270 -0
  136. package/docs/example-agents/benny.md +186 -0
  137. package/docs/example-agents/bugbot.md +231 -0
  138. package/docs/example-agents/codebase-wiki.md +174 -0
  139. package/docs/example-agents/codeowners-review.md +195 -0
  140. package/docs/example-agents/concierge.md +205 -0
  141. package/docs/example-agents/fsd.md +330 -0
  142. package/docs/example-agents/index.md +102 -0
  143. package/docs/example-agents/knowledge-base.md +171 -0
  144. package/docs/example-agents/security-reviewer.md +296 -0
  145. package/docs/example-agents/slack-agent.md +146 -0
  146. package/docs/example-agents/weather-agent.md +302 -0
  147. package/docs/reference/cli.md +546 -147
  148. package/package.json +1 -1
  149. package/src/ab.ts +9 -261
  150. package/src/bin/agent-serve.ts +46 -7
  151. package/src/evals.ts +5 -119
  152. package/src/index.ts +2 -0
  153. package/src/internal/ab-collector.ts +12 -22
  154. package/src/internal/ab-snapshot.ts +2 -4
  155. package/src/internal/cli-ax.ts +551 -104
  156. package/src/internal/cli-deploy.ts +1 -1
  157. package/src/internal/discovery.ts +2 -2
  158. package/src/internal/eval-run-store.ts +91 -100
  159. package/src/internal/evals-client.ts +431 -0
  160. package/src/internal/init-project.ts +1 -0
  161. package/src/internal/playground-proxy.ts +5 -5
  162. package/src/internal/resolve-prod-target.ts +101 -3
  163. package/src/internal/server.ts +17 -3
  164. package/src/internal/session-engine.ts +9 -29
  165. package/src/internal/storage-coordinator.ts +109 -101
  166. package/src/storage.ts +79 -14
  167. package/dist/docs/assets/chunks/@localSearchIndexroot.QwK5BtEH.js +0 -1
  168. package/dist/docs/assets/deployment.md.DTKwE15Z.js +0 -14
  169. package/dist/docs/assets/deployment.md.DTKwE15Z.lean.js +0 -1
  170. package/dist/docs/assets/index.md.Cylk70gg.js +0 -20
  171. package/dist/docs/assets/reference_cli.md.Bv6pOxcF.js +0 -38
  172. package/dist/docs/assets/reference_cli.md.Bv6pOxcF.lean.js +0 -1
  173. package/dist/internal/json-dir-store.js +0 -100
  174. package/dist/playground/assets/cursor-icons-outline-BxTT_FVJ.woff2 +0 -0
  175. package/dist/playground/assets/index-BEauYlII.css +0 -1
  176. package/dist/playground/assets/index-BtM0wEGg.js +0 -319
  177. package/src/internal/json-dir-store.ts +0 -109
@@ -0,0 +1,262 @@
1
+ /**
2
+ * HTTP client for playground eval batches (`/v1/dev/evals/runs`).
3
+ *
4
+ * Used by `agentkit eval --prod` (or `--url`) so the batch runs on the serve
5
+ * process and is mirrored to `defineStorage` when an `evals` table is
6
+ * configured. Without those flags, eval keeps the in-process ephemeral path
7
+ * in `cli-ax.ts`.
8
+ */
9
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
+ return new (P || (P = Promise))(function (resolve, reject) {
12
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16
+ });
17
+ };
18
+ import { matchesEvalIdFilter } from "../evals.js";
19
+ import { mergeRequestHeaders } from "./request-headers.js";
20
+ const DEFAULT_POLL_MS = 1000;
21
+ export class RemoteEvalError extends Error {
22
+ constructor(message, status, code, activeRunId) {
23
+ super(message);
24
+ this.status = status;
25
+ this.code = code;
26
+ this.activeRunId = activeRunId;
27
+ this.name = "RemoteEvalError";
28
+ }
29
+ }
30
+ /**
31
+ * Start a batch on the target serve via `POST /v1/dev/evals/runs`, poll until
32
+ * terminal, and return CLI-shaped case results.
33
+ */
34
+ export function runRemoteEvals(options) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ var _a;
37
+ var _b, _c;
38
+ const baseUrl = options.baseUrl.replace(/\/$/, "");
39
+ const fetchImpl = (_b = options.fetchImpl) !== null && _b !== void 0 ? _b : fetch;
40
+ const auth = {
41
+ bearerToken: options.bearerToken,
42
+ headers: options.headers,
43
+ };
44
+ const started = yield startRemoteEvalRun({
45
+ baseUrl,
46
+ auth,
47
+ fetchImpl,
48
+ filterIds: options.filterIds,
49
+ tags: options.tags,
50
+ timeoutMs: options.timeoutMs,
51
+ verbose: options.verbose,
52
+ signal: options.signal,
53
+ });
54
+ (_a = options.onSnapshot) === null || _a === void 0 ? void 0 : _a.call(options, started);
55
+ const snapshot = yield pollRemoteEvalRun({
56
+ baseUrl,
57
+ runId: started.runId,
58
+ auth,
59
+ fetchImpl,
60
+ pollMs: (_c = options.pollMs) !== null && _c !== void 0 ? _c : DEFAULT_POLL_MS,
61
+ signal: options.signal,
62
+ onSnapshot: options.onSnapshot,
63
+ });
64
+ return { snapshot, results: snapshotToEvalRunResults(snapshot) };
65
+ });
66
+ }
67
+ /** List datapoints from `GET /v1/dev/evals` (same surface a remote run uses). */
68
+ export function listRemoteEvals(args) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ var _a, _b;
71
+ const baseUrl = args.baseUrl.replace(/\/$/, "");
72
+ const fetchImpl = (_a = args.fetchImpl) !== null && _a !== void 0 ? _a : fetch;
73
+ let resp;
74
+ try {
75
+ resp = yield fetchImpl(`${baseUrl}/v1/dev/evals`, {
76
+ headers: mergeRequestHeaders(args.auth),
77
+ signal: args.signal,
78
+ });
79
+ }
80
+ catch (error) {
81
+ throw new RemoteEvalError(error instanceof Error ? error.message : "Could not list evals.", undefined, "start_failed");
82
+ }
83
+ if (!resp.ok) {
84
+ throw new RemoteEvalError(`Could not list evals (HTTP ${resp.status}).`, resp.status, "start_failed");
85
+ }
86
+ const body = (yield resp.json());
87
+ const listed = [];
88
+ for (const row of (_b = body.evals) !== null && _b !== void 0 ? _b : []) {
89
+ if (typeof row.id !== "string" || row.id === "") {
90
+ continue;
91
+ }
92
+ if (typeof row.fileId !== "string" || row.fileId === "") {
93
+ continue;
94
+ }
95
+ const tags = Array.isArray(row.tags)
96
+ ? row.tags.filter((t) => typeof t === "string")
97
+ : undefined;
98
+ listed.push(Object.assign(Object.assign({ id: row.id, fileId: row.fileId }, (typeof row.description === "string"
99
+ ? { description: row.description }
100
+ : {})), (tags === undefined || tags.length === 0 ? {} : { tags })));
101
+ }
102
+ let selected = listed;
103
+ if (args.filterIds !== undefined && args.filterIds.length > 0) {
104
+ selected = selected.filter((e) => args.filterIds.some((f) => matchesEvalIdFilter(e.id, f)));
105
+ }
106
+ if (args.tags !== undefined && args.tags.length > 0) {
107
+ selected = selected.filter((e) => { var _a; return ((_a = e.tags) !== null && _a !== void 0 ? _a : []).some((t) => args.tags.includes(t)); });
108
+ }
109
+ return selected;
110
+ });
111
+ }
112
+ export function startRemoteEvalRun(args) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ var _a;
115
+ const baseUrl = args.baseUrl.replace(/\/$/, "");
116
+ const fetchImpl = (_a = args.fetchImpl) !== null && _a !== void 0 ? _a : fetch;
117
+ const body = {};
118
+ if (args.filterIds !== undefined && args.filterIds.length > 0) {
119
+ body.filterIds = args.filterIds;
120
+ }
121
+ if (args.tags !== undefined && args.tags.length > 0) {
122
+ body.tags = args.tags;
123
+ }
124
+ if (args.timeoutMs !== undefined) {
125
+ body.timeoutMs = args.timeoutMs;
126
+ }
127
+ if (args.verbose === true) {
128
+ body.verbose = true;
129
+ }
130
+ let resp;
131
+ try {
132
+ resp = yield fetchImpl(`${baseUrl}/v1/dev/evals/runs`, {
133
+ method: "POST",
134
+ headers: Object.assign({ "content-type": "application/json" }, mergeRequestHeaders(args.auth)),
135
+ body: JSON.stringify(body),
136
+ signal: args.signal,
137
+ });
138
+ }
139
+ catch (error) {
140
+ throw new RemoteEvalError(error instanceof Error ? error.message : "Could not start eval run.", undefined, "start_failed");
141
+ }
142
+ const json = (yield resp.json().catch(() => ({})));
143
+ if (json.error === "no_matching_evals") {
144
+ throw new RemoteEvalError("No matching evals found.", 404, "no_matching_evals");
145
+ }
146
+ if (resp.status === 409 || json.error === "eval_run_in_progress") {
147
+ throw new RemoteEvalError(json.activeRunId !== undefined && json.activeRunId !== ""
148
+ ? `An eval run is already in progress (${json.activeRunId}).`
149
+ : "An eval run is already in progress.", 409, "eval_run_in_progress", typeof json.activeRunId === "string" ? json.activeRunId : undefined);
150
+ }
151
+ if (!resp.ok) {
152
+ const detail = typeof json.message === "string" && json.message !== ""
153
+ ? json.message
154
+ : typeof json.error === "string" && json.error !== ""
155
+ ? json.error
156
+ : `HTTP ${resp.status}`;
157
+ throw new RemoteEvalError(`Could not start eval run: ${detail}`, resp.status, "start_failed");
158
+ }
159
+ if (typeof json.runId !== "string" || json.runId === "") {
160
+ throw new RemoteEvalError("Eval start response missing runId.", undefined, "start_failed");
161
+ }
162
+ return json;
163
+ });
164
+ }
165
+ /** One-shot `GET /v1/dev/evals/runs/:runId` (no polling). */
166
+ export function getRemoteEvalRun(args) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ var _a;
169
+ const baseUrl = args.baseUrl.replace(/\/$/, "");
170
+ const fetchImpl = (_a = args.fetchImpl) !== null && _a !== void 0 ? _a : fetch;
171
+ let resp;
172
+ try {
173
+ resp = yield fetchImpl(`${baseUrl}/v1/dev/evals/runs/${encodeURIComponent(args.runId)}`, {
174
+ headers: mergeRequestHeaders(args.auth),
175
+ signal: args.signal,
176
+ });
177
+ }
178
+ catch (error) {
179
+ throw new RemoteEvalError(error instanceof Error ? error.message : "Could not fetch eval run.", undefined, "poll_failed");
180
+ }
181
+ if (resp.status === 404) {
182
+ throw new RemoteEvalError(`Unknown eval run ${args.runId}.`, 404, "unknown_eval_run");
183
+ }
184
+ if (!resp.ok) {
185
+ throw new RemoteEvalError(`Could not fetch eval run (HTTP ${resp.status}).`, resp.status, "poll_failed");
186
+ }
187
+ return (yield resp.json());
188
+ });
189
+ }
190
+ /** Recent batches from `GET /v1/dev/evals/runs`. */
191
+ export function listRemoteEvalRuns(args) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ var _a;
194
+ const baseUrl = args.baseUrl.replace(/\/$/, "");
195
+ const fetchImpl = (_a = args.fetchImpl) !== null && _a !== void 0 ? _a : fetch;
196
+ let resp;
197
+ try {
198
+ resp = yield fetchImpl(`${baseUrl}/v1/dev/evals/runs`, {
199
+ headers: mergeRequestHeaders(args.auth),
200
+ signal: args.signal,
201
+ });
202
+ }
203
+ catch (error) {
204
+ throw new RemoteEvalError(error instanceof Error ? error.message : "Could not list eval runs.", undefined, "poll_failed");
205
+ }
206
+ if (!resp.ok) {
207
+ throw new RemoteEvalError(`Could not list eval runs (HTTP ${resp.status}).`, resp.status, "poll_failed");
208
+ }
209
+ const body = (yield resp.json());
210
+ const runs = Array.isArray(body.runs)
211
+ ? body.runs.filter((r) => r !== null &&
212
+ typeof r === "object" &&
213
+ typeof r.runId === "string")
214
+ : [];
215
+ return Object.assign({ runs }, (typeof body.activeRunId === "string" && body.activeRunId !== ""
216
+ ? { activeRunId: body.activeRunId }
217
+ : {}));
218
+ });
219
+ }
220
+ export function pollRemoteEvalRun(args) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ var _a, _b;
223
+ var _c;
224
+ const pollMs = (_c = args.pollMs) !== null && _c !== void 0 ? _c : DEFAULT_POLL_MS;
225
+ let lastJson = "";
226
+ for (;;) {
227
+ if (((_a = args.signal) === null || _a === void 0 ? void 0 : _a.aborted) === true) {
228
+ throw new RemoteEvalError("Eval wait aborted.", undefined, "aborted");
229
+ }
230
+ const snap = yield getRemoteEvalRun(args);
231
+ const serialized = JSON.stringify(snap);
232
+ if (serialized !== lastJson) {
233
+ lastJson = serialized;
234
+ (_b = args.onSnapshot) === null || _b === void 0 ? void 0 : _b.call(args, snap);
235
+ }
236
+ if (snap.status !== "running") {
237
+ return snap;
238
+ }
239
+ yield sleep(pollMs, args.signal);
240
+ }
241
+ });
242
+ }
243
+ export function snapshotToEvalRunResults(snapshot) {
244
+ return snapshot.cases.map((c) => { var _a, _b, _c, _d; return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ id: c.id, path: c.fileId }, (c.description === undefined ? {} : { description: c.description })), { ok: c.ok === true, assertions: (_a = c.assertions) !== null && _a !== void 0 ? _a : [] }), (c.sessionId === undefined ? {} : { sessionId: c.sessionId })), { inputs: (_b = c.inputs) !== null && _b !== void 0 ? _b : [] }), (c.finalText === undefined ? {} : { finalText: c.finalText })), (c.tools === undefined ? {} : { tools: c.tools })), (c.toolCalls === undefined ? {} : { toolCalls: c.toolCalls })), (c.error === undefined ? {} : { error: c.error })), { logs: (_c = c.logs) !== null && _c !== void 0 ? _c : [], durationMs: (_d = c.durationMs) !== null && _d !== void 0 ? _d : 0 })); });
245
+ }
246
+ function sleep(ms, signal) {
247
+ return new Promise((resolve, reject) => {
248
+ if ((signal === null || signal === void 0 ? void 0 : signal.aborted) === true) {
249
+ reject(new RemoteEvalError("Eval wait aborted.", undefined, "aborted"));
250
+ return;
251
+ }
252
+ const timer = setTimeout(() => {
253
+ signal === null || signal === void 0 ? void 0 : signal.removeEventListener("abort", onAbort);
254
+ resolve();
255
+ }, ms);
256
+ const onAbort = () => {
257
+ clearTimeout(timer);
258
+ reject(new RemoteEvalError("Eval wait aborted.", undefined, "aborted"));
259
+ };
260
+ signal === null || signal === void 0 ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
261
+ });
262
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"init-project.d.ts","sourceRoot":"","sources":["../../src/internal/init-project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiBH,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEhD,MAAM,WA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C;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,kBAAkB,GAAG,0BAA0B,GACzD,oBAAoB,CAAC;AAMvB;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,0BAA0B,GAClC,MAAM,CAkBR;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAgBzE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAErE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAQpB;AAwBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;CACnB,GAAG,MAAM,EAAE,CAEX;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAuBrC"}
@@ -309,6 +309,7 @@ Evals:
309
309
  Required: evals/evals.config.ts with defineEvalConfig({ maxConcurrency })
310
310
  (hard-capped at 200 due to model provider request limits)
311
311
  Run: ${CLI_COMMAND_NAME} eval [--json] [evalId...]
312
+ (pass --prod to run against the hosted deployment)
312
313
 
313
314
  See AGENTS.md in the ${PACKAGE_NAME} package for the full loop.
314
315
  `);
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Runtime for `definePersistence` (`agent/persistence.ts`).
3
+ *
4
+ * The coordinator is the single funnel between the engine's hot paths and
5
+ * the author's key-value sink. The sink is four functions (`put` / `get` /
6
+ * `delete` / `list`); the coordinator owns everything else: it mints every
7
+ * key from the versioned scheme ({@link persistenceKeys}), coalesces
8
+ * session records and batches event chunks per turn (or debounce window),
9
+ * serializes delivery on one bounded queue per agent, and isolates
10
+ * failures — a throwing sink is logged and its write dropped; persistence
11
+ * must never stall or fail a turn.
12
+ *
13
+ * Scaling shape: sessions, evals, and A/Bs all reduce to keyed puts on the
14
+ * same queue, so one author-owned sink covers every domain, and new
15
+ * domains are new key prefixes — not new config surface.
16
+ */
17
+ import type { ABSamplePersistence } from "../ab.js";
18
+ import type { EvalRunPersistence } from "../evals.js";
19
+ import { type PersistenceContext, type PersistenceDefinition, type ResolvedPersistencePolicy } from "../persistence.js";
20
+ import type { SessionEvent, SessionRecord } from "../types.js";
21
+ import type { ABSnapshot } from "./ab-snapshot.js";
22
+ export interface PersistenceCoordinatorOptions {
23
+ definition: PersistenceDefinition;
24
+ agentName: string;
25
+ projectRoot: string;
26
+ logger: (line: string) => void;
27
+ }
28
+ export declare class PersistenceCoordinator {
29
+ readonly policy: ResolvedPersistencePolicy;
30
+ private readonly definition;
31
+ private readonly agentName;
32
+ private readonly projectRoot;
33
+ private readonly logger;
34
+ /** Per-session pending state (events + coalesced record). */
35
+ private readonly buffers;
36
+ /**
37
+ * Last continuation key written to the sink per session, so a token
38
+ * change emits a delete for the stale index entry alongside the new put.
39
+ */
40
+ private readonly continuationIndex;
41
+ /** Single delivery chain: writes reach the sink serialized, in order. */
42
+ private queue;
43
+ /** Ops on the queue not yet delivered (bounded by MAX_PENDING_OPS). */
44
+ private pending;
45
+ /** Ops dropped because the queue was full. */
46
+ private dropped;
47
+ private lastAbSnapshotAt;
48
+ private closed;
49
+ constructor(options: PersistenceCoordinatorOptions);
50
+ /** Durable session-record update (engine calls after every store save). */
51
+ sessionRecord(record: SessionRecord): void;
52
+ /** One appended session event (engine calls from its dispatch funnel). */
53
+ event(event: SessionEvent): void;
54
+ /**
55
+ * A boundary event's dispatch settled: channel/hook handlers ran and
56
+ * their record updates (channel state, continuation tokens) are
57
+ * buffered. This — not the append — is the turn-end flush point, so the
58
+ * persisted session record includes the boundary event's own handler
59
+ * mutations. Debounced batching intentionally ignores boundaries.
60
+ */
61
+ eventDispatched(event: SessionEvent): void;
62
+ /** Flush everything buffered for one session (ordered: events, record). */
63
+ flushSession(sessionId: string, reason?: PersistenceContext["reason"]): void;
64
+ /**
65
+ * Index maintenance for `continuation/{channelId}/{token}` → sessionId:
66
+ * put the current token, delete the previous one when it changed.
67
+ */
68
+ private continuationOps;
69
+ /** Whether the sink can serve the startup bulk restore (`list`). */
70
+ get canBulkRestore(): boolean;
71
+ /**
72
+ * Saved session records for this agent (startup restore). Errors are
73
+ * logged and read as "nothing saved" — a broken store must never block
74
+ * serve start.
75
+ */
76
+ listSessions(): Promise<SessionRecord[]>;
77
+ /**
78
+ * Saved event stream for one session: chunk values concatenated in key
79
+ * order (chunks are keyed by their first event's index, zero-padded, so
80
+ * ascending key order is append order). Errors read as an empty stream.
81
+ */
82
+ listSessionEvents(sessionId: string): Promise<SessionEvent[]>;
83
+ /**
84
+ * One saved session by channel continuation key (lazy restore). Unlike
85
+ * the startup reads, sink errors **propagate**: a failing store must
86
+ * fail the follow-up (which the caller can retry) rather than read as
87
+ * "unknown token" — that would mint a new session under the same
88
+ * continuation key and permanently shadow the real one on this host.
89
+ * A definitive miss (no index entry, or a write-only sink without
90
+ * `get`) resolves undefined.
91
+ */
92
+ getSessionByContinuation(channelId: string, continuationKey: string): Promise<SessionRecord | undefined>;
93
+ /**
94
+ * Adapter for {@link EvalRunPersistence} so the playground eval store
95
+ * can fall back to this sink when `evals.config.ts` sets no
96
+ * `persistRuns`.
97
+ */
98
+ asEvalRunPersistence(): EvalRunPersistence;
99
+ /**
100
+ * Adapter for {@link ABSamplePersistence} so the AB collector can fall
101
+ * back to this sink when `ab.config.ts` sets no `persistSamples`.
102
+ */
103
+ asABSamplePersistence(): ABSamplePersistence;
104
+ /**
105
+ * Refresh the persisted aggregate A/B snapshot, throttled to once per
106
+ * {@link AB_SNAPSHOT_MIN_INTERVAL_MS} (the playground recomputes the
107
+ * fold on every `GET /v1/abs` poll).
108
+ */
109
+ abSnapshot(snapshot: ABSnapshot): void;
110
+ /** Latest persisted aggregate A/B snapshot; errors read as absent. */
111
+ getLatestAbSnapshot(): Promise<ABSnapshot | undefined>;
112
+ /**
113
+ * Flush all buffers and drain the queue, giving the sink at most
114
+ * {@link CLOSE_DRAIN_TIMEOUT_MS} — a hung sink must not stall shutdown
115
+ * past the pod grace period. Called from engine close.
116
+ */
117
+ close(): Promise<void>;
118
+ /** Pending deliveries (exposed for tests and drain instrumentation). */
119
+ whenIdle(): Promise<void>;
120
+ private buffer;
121
+ private armDebounce;
122
+ /** `list` wrapper for the startup reads: missing hook or throw ⇒ empty. */
123
+ private tryList;
124
+ private enqueue;
125
+ private context;
126
+ }
127
+ //# sourceMappingURL=persistence-coordinator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence-coordinator.d.ts","sourceRoot":"","sources":["../../src/internal/persistence-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAkB,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAE1B,KAAK,yBAAyB,EAE/B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAa,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAyCnD,MAAM,WAAW,6BAA6B;IAC5C,UAAU,EAAE,qBAAqB,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AASD,qBAAa,sBAAsB;IACjC,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC;IAE3C,OAAO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CAgDpC;IAMD;;;;OAIG;IACH,oBAAoB,IAAI,kBAAkB,CAkCzC;IAMD;;;OAGG;IACH,qBAAqB,IAAI,mBAAmB,CAmB3C;IAED;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,UAAU,GAAG,IAAI,CAmBrC;IAED,sEAAsE;IAChE,mBAAmB,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAiB3D;IAMD;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAqB3B;IAED,wEAAwE;IACxE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAExB;IAED,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,WAAW;IAgBnB,2EAA2E;YAC7D,OAAO;IAkBrB,OAAO,CAAC,OAAO;IAqCf,OAAO,CAAC,OAAO;CAGhB"}
@@ -14,9 +14,9 @@
14
14
  * request-targets are rejected so injected headers never leave the configured
15
15
  * upstream.
16
16
  *
17
- * When `refreshUpstream` is provided (hosted `--prod`), credentials are
18
- * re-minted shortly before `expiresAt` and once on upstream 401 so a long
19
- * playground session does not require restarting the CLI.
17
+ * When `refreshUpstream` is provided (e.g. short-lived upstream tokens),
18
+ * credentials are re-minted shortly before `expiresAt` and once on upstream
19
+ * 401 so a long playground session does not require restarting the CLI.
20
20
  */
21
21
  import { createServer } from "node:http";
22
22
  import { openBrowser } from "./open-browser.js";
@@ -49,8 +49,8 @@ export interface StartPlaygroundProxyArgs {
49
49
  /** Initial engineAccess expiry (ISO); enables proactive refresh. */
50
50
  expiresAt?: string;
51
51
  /**
52
- * Re-mint upstream URL + headers (hosted `--prod`). Single-flighted across
53
- * concurrent browser requests; called near expiry and once on 401.
52
+ * Re-mint upstream URL + headers. Single-flighted across concurrent browser
53
+ * requests; called near expiry and once on 401.
54
54
  */
55
55
  refreshUpstream?: () => Promise<PlaygroundUpstreamAccess>;
56
56
  /** Bind port; `0` = ephemeral. */
@@ -14,9 +14,9 @@
14
14
  * request-targets are rejected so injected headers never leave the configured
15
15
  * upstream.
16
16
  *
17
- * When `refreshUpstream` is provided (hosted `--prod`), credentials are
18
- * re-minted shortly before `expiresAt` and once on upstream 401 so a long
19
- * playground session does not require restarting the CLI.
17
+ * When `refreshUpstream` is provided (e.g. short-lived upstream tokens),
18
+ * credentials are re-minted shortly before `expiresAt` and once on upstream
19
+ * 401 so a long playground session does not require restarting the CLI.
20
20
  */
21
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -30,11 +30,41 @@ export interface ResolvedProdTarget {
30
30
  slug: string;
31
31
  expiresAt: string;
32
32
  }
33
+ /**
34
+ * Thrown when a hosted deployment cannot be resolved. `notFound` is true
35
+ * when the deployment does not exist, so callers can suggest deploying
36
+ * (or running locally) instead of surfacing a bare API error.
37
+ */
38
+ export declare class ProdTargetError extends Error {
39
+ readonly options: {
40
+ slug: string;
41
+ notFound?: boolean;
42
+ };
43
+ constructor(message: string, options?: {
44
+ slug: string;
45
+ notFound?: boolean;
46
+ });
47
+ get slug(): string;
48
+ get notFound(): boolean;
49
+ }
33
50
  /**
34
51
  * Look up a running deployment and return its engineAccess URL/headers.
35
52
  * Throws {@link Error} with a CLI-ready message on failure.
36
53
  */
37
54
  export declare function resolveProdTarget(options: ResolveProdTargetOptions): Promise<ResolvedProdTarget>;
55
+ export interface ResolvedProdAliasPlayground {
56
+ /** Hosted playground URL on the API alias (SPA owns alias-token sign-in). */
57
+ playgroundUrl: string;
58
+ slug: string;
59
+ }
60
+ /**
61
+ * Look up a running deployment and return its stable alias playground URL.
62
+ * Does not mint `engineAccess` — the browser signs in with the alias token.
63
+ * Throws {@link Error} with a CLI-ready message on failure.
64
+ */
65
+ export declare function resolveProdAliasPlaygroundUrl(options: ResolveProdTargetOptions & {
66
+ sessionId?: string;
67
+ }): Promise<ResolvedProdAliasPlayground>;
38
68
  /** Resolve the deployment slug the same way `deploy` does for a single dir. */
39
69
  export declare function resolveProdSlug(options: {
40
70
  dir: string;
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-prod-target.d.ts","sourceRoot":"","sources":["../../src/internal/resolve-prod-target.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGrE,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,gDAAgD;IAChD,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAuF7B;AAiBD,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,MAAM,CAgBT"}
1
+ {"version":3,"file":"resolve-prod-target.d.ts","sourceRoot":"","sources":["../../src/internal/resolve-prod-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W,2BAA2B;IAC1C,6EAA6E;IAC7E,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,wBAAwB,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACzD,OAAO,CAAC,2BAA2B,CAAC,CAyDtC;AAiBD,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,MAAM,CAgBT"}
@@ -29,6 +29,24 @@ export const PROD_ENGINE_WAKE_HEADERS = {
29
29
  "x-anyrun-hibernation-lower-bound-s": "1800",
30
30
  "x-anyrun-hibernation-upper-bound-s": "3600",
31
31
  };
32
+ /**
33
+ * Thrown when a hosted deployment cannot be resolved. `notFound` is true
34
+ * when the deployment does not exist, so callers can suggest deploying
35
+ * (or running locally) instead of surfacing a bare API error.
36
+ */
37
+ export class ProdTargetError extends Error {
38
+ constructor(message, options = { slug: "" }) {
39
+ super(message);
40
+ this.options = options;
41
+ this.name = "ProdTargetError";
42
+ }
43
+ get slug() {
44
+ return this.options.slug;
45
+ }
46
+ get notFound() {
47
+ return this.options.notFound === true;
48
+ }
49
+ }
32
50
  /**
33
51
  * Look up a running deployment and return its engineAccess URL/headers.
34
52
  * Throws {@link Error} with a CLI-ready message on failure.
@@ -45,7 +63,9 @@ export function resolveProdTarget(options) {
45
63
  err,
46
64
  });
47
65
  if (typeof auth === "number") {
48
- throw new Error(`Could not resolve Cursor credentials/team for --prod (see above).`);
66
+ // Not "--prod": `eval` resolves the hosted deployment by default,
67
+ // without any flag.
68
+ throw new Error(`Could not resolve Cursor credentials/team for the hosted deployment (see above).`);
49
69
  }
50
70
  // A hibernated engine can briefly omit engineAccess while getPod fails
51
71
  // during wake. Retry a few times before surfacing "not reachable yet".
@@ -61,7 +81,7 @@ export function resolveProdTarget(options) {
61
81
  }
62
82
  catch (error) {
63
83
  if (error instanceof DeployApiError) {
64
- throw new Error(`Deployment "${slug}" (team ${auth.teamId}): ${error.message}`);
84
+ throw new ProdTargetError(`Deployment "${slug}" (team ${auth.teamId}): ${error.message}`, { slug, notFound: error.status === 404 });
65
85
  }
66
86
  throw error;
67
87
  }
@@ -102,6 +122,58 @@ export function resolveProdTarget(options) {
102
122
  };
103
123
  });
104
124
  }
125
+ /**
126
+ * Look up a running deployment and return its stable alias playground URL.
127
+ * Does not mint `engineAccess` — the browser signs in with the alias token.
128
+ * Throws {@link Error} with a CLI-ready message on failure.
129
+ */
130
+ export function resolveProdAliasPlaygroundUrl(options) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ var _a;
133
+ const err = (_a = options.err) !== null && _a !== void 0 ? _a : ((text) => void process.stderr.write(text));
134
+ const slug = resolveProdSlug(options);
135
+ const auth = yield resolveDeployAuth({
136
+ team: options.team,
137
+ apiKey: options.apiKey,
138
+ fetchImpl: options.fetchImpl,
139
+ err,
140
+ });
141
+ if (typeof auth === "number") {
142
+ throw new Error(`Could not resolve Cursor credentials/team for the hosted deployment (see above).`);
143
+ }
144
+ let detail;
145
+ try {
146
+ detail = yield auth.client.getDeployment({
147
+ teamId: auth.teamId,
148
+ slug,
149
+ });
150
+ }
151
+ catch (error) {
152
+ if (error instanceof DeployApiError) {
153
+ throw new Error(`Deployment "${slug}" (team ${auth.teamId}): ${error.message}`);
154
+ }
155
+ throw error;
156
+ }
157
+ const statusOk = detail.status === "running" || detail.status === "degraded";
158
+ if (!statusOk) {
159
+ const lastError = detail.lastError === null || detail.lastError === undefined
160
+ ? ""
161
+ : ` ${sanitizeCustomerFacingDetail(detail.lastError)}`;
162
+ throw new Error(`Deployment "${slug}" is ${detail.status}, not running.${lastError}\n` +
163
+ `Deploy or wait: \`${CLI} deploy --slug ${slug}\` / \`${CLI} deployment ${slug}\``);
164
+ }
165
+ const aliasBase = auth.client.aliasUrl(detail.engineAlias).replace(/\/$/, "");
166
+ const base = `${aliasBase}/playground`;
167
+ const sessionId = options.sessionId !== undefined && options.sessionId.trim() !== ""
168
+ ? options.sessionId.trim()
169
+ : undefined;
170
+ const playgroundUrl = sessionId === undefined
171
+ ? base
172
+ : `${base}?sessionId=${encodeURIComponent(sessionId)}`;
173
+ err(`${stderrPalette().dim(`Using hosted deployment "${slug}".`)}\n`);
174
+ return { playgroundUrl, slug };
175
+ });
176
+ }
105
177
  /** Strip obvious hosting internals from customer-facing error fragments. */
106
178
  function sanitizeCustomerFacingDetail(message) {
107
179
  return message
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/internal/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2BH,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAOhB,YAAY,EACb,MAAM,aAAa,CAAC;AAoFrB,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAapE,8EAA8E;AAC9E,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,CAAC;CACvB;AAYD,6EAA6E;AAC7E,MAAM,WAAW,0BAA0B;IACzC,oEAAoE;IACpE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,UAAU,EAAE,EACpB,OAAO,GAAE,YAAY,GAAG,0BAA+B,GACtD,OAAO,CAAC,gBAAgB,CAAC,CAylB3B"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/internal/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2BH,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAOhB,YAAY,EACb,MAAM,aAAa,CAAC;AAoFrB,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAapE,8EAA8E;AAC9E,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,CAAC;CACvB;AAYD,6EAA6E;AAC7E,MAAM,WAAW,0BAA0B;IACzC,oEAAoE;IACpE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,UAAU,EAAE,EACpB,OAAO,GAAE,YAAY,GAAG,0BAA+B,GACtD,OAAO,CAAC,gBAAgB,CAAC,CA2lB3B"}