@cursor/july 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +16 -5
- package/README.md +8 -9
- package/dist/bin/agent-serve.d.ts +3 -1
- package/dist/bin/agent-serve.d.ts.map +1 -1
- package/dist/bin/agent-serve.js +389 -152
- package/dist/docs/404.html +2 -2
- package/dist/docs/ab.html +3 -3
- package/dist/docs/assets/{app.Oje4vhlk.js → app.BR0RbIdx.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DtIOQzGj.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.H5XZ2zCB.js → VPLocalSearchBox.qjsVTneI.js} +1 -1
- package/dist/docs/assets/chunks/{theme.CTR_TuaE.js → theme.2Kg8jIp_.js} +2 -2
- package/dist/docs/assets/{quickstart.md.CfU8_uTC.js → quickstart.md.BU6Iwi_9.js} +18 -6
- package/dist/docs/assets/{reference_cli.md.DA730zCu.js → reference_cli.md.Bv6pOxcF.js} +11 -6
- package/dist/docs/assets/{reference_cli.md.DA730zCu.lean.js → reference_cli.md.Bv6pOxcF.lean.js} +1 -1
- package/dist/docs/building-with-agents.html +3 -3
- package/dist/docs/concepts.html +3 -3
- package/dist/docs/deployment.html +3 -3
- package/dist/docs/evals.html +3 -3
- package/dist/docs/guides/agent-to-agent.html +3 -3
- package/dist/docs/guides/cloud-runtime.html +3 -3
- package/dist/docs/guides/github.html +3 -3
- package/dist/docs/guides/human-in-the-loop.html +3 -3
- package/dist/docs/guides/slack.html +3 -3
- package/dist/docs/guides/webhooks.html +3 -3
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +3 -3
- package/dist/docs/index.html +3 -3
- package/dist/docs/quickstart.html +22 -10
- package/dist/docs/reference/agent-config.html +3 -3
- package/dist/docs/reference/channels.html +3 -3
- package/dist/docs/reference/cli.html +14 -9
- package/dist/docs/reference/connections.html +3 -3
- package/dist/docs/reference/hooks.html +3 -3
- package/dist/docs/reference/http-api.html +3 -3
- package/dist/docs/reference/instructions.html +3 -3
- package/dist/docs/reference/playground.html +3 -3
- package/dist/docs/reference/project-layout.html +3 -3
- package/dist/docs/reference/schedules.html +3 -3
- package/dist/docs/reference/sessions.html +3 -3
- package/dist/docs/reference/skills.html +3 -3
- package/dist/docs/reference/subagents.html +3 -3
- package/dist/docs/reference/tools.html +3 -3
- package/dist/docs/scaffolding-agents.html +3 -3
- package/dist/docs/storage.html +3 -3
- package/dist/docs/troubleshooting.html +3 -3
- package/dist/internal/chat-client.d.ts +29 -3
- package/dist/internal/chat-client.d.ts.map +1 -1
- package/dist/internal/chat-client.js +180 -27
- package/dist/internal/cli-ax.d.ts +75 -2
- package/dist/internal/cli-ax.d.ts.map +1 -1
- package/dist/internal/cli-ax.js +600 -52
- package/dist/internal/cli-cursor.d.ts.map +1 -1
- package/dist/internal/cli-cursor.js +8 -36
- package/dist/internal/cli-deploy.d.ts +59 -3
- package/dist/internal/cli-deploy.d.ts.map +1 -1
- package/dist/internal/cli-deploy.js +316 -38
- package/dist/internal/cursor/credentials.d.ts +9 -0
- package/dist/internal/cursor/credentials.d.ts.map +1 -1
- package/dist/internal/cursor/credentials.js +12 -0
- package/dist/internal/deploy-client.d.ts +9 -1
- package/dist/internal/deploy-client.d.ts.map +1 -1
- package/dist/internal/deploy-client.js +23 -3
- package/dist/internal/deploy-source.d.ts +35 -0
- package/dist/internal/deploy-source.d.ts.map +1 -0
- package/dist/internal/deploy-source.js +118 -0
- package/dist/internal/discovery.d.ts +11 -0
- package/dist/internal/discovery.d.ts.map +1 -1
- package/dist/internal/discovery.js +43 -14
- package/dist/internal/eval-run-store.d.ts.map +1 -1
- package/dist/internal/eval-run-store.js +2 -1
- package/dist/internal/eval-runner.d.ts +2 -0
- package/dist/internal/eval-runner.d.ts.map +1 -1
- package/dist/internal/eval-runner.js +2 -0
- package/dist/internal/event-mapper.d.ts +54 -1
- package/dist/internal/event-mapper.d.ts.map +1 -1
- package/dist/internal/event-mapper.js +151 -41
- package/dist/internal/init-project.d.ts +88 -1
- package/dist/internal/init-project.d.ts.map +1 -1
- package/dist/internal/init-project.js +221 -31
- package/dist/internal/install-cursor-skills.d.ts +64 -0
- package/dist/internal/install-cursor-skills.d.ts.map +1 -0
- package/dist/internal/install-cursor-skills.js +274 -0
- package/dist/internal/logs-client.d.ts +60 -0
- package/dist/internal/logs-client.d.ts.map +1 -0
- package/dist/internal/logs-client.js +311 -0
- package/dist/internal/open-browser.d.ts +5 -0
- package/dist/internal/open-browser.d.ts.map +1 -0
- package/dist/internal/open-browser.js +34 -0
- package/dist/internal/playground/toolchain.d.ts.map +1 -1
- package/dist/internal/playground/toolchain.js +16 -11
- package/dist/internal/playground-proxy.d.ts +69 -0
- package/dist/internal/playground-proxy.d.ts.map +1 -0
- package/dist/internal/playground-proxy.js +468 -0
- package/dist/internal/prompt-context.d.ts +35 -0
- package/dist/internal/prompt-context.d.ts.map +1 -0
- package/dist/internal/prompt-context.js +71 -0
- package/dist/internal/request-headers.d.ts +11 -0
- package/dist/internal/request-headers.d.ts.map +1 -0
- package/dist/internal/request-headers.js +14 -0
- package/dist/internal/resolve-prod-target.d.ts +42 -0
- package/dist/internal/resolve-prod-target.d.ts.map +1 -0
- package/dist/internal/resolve-prod-target.js +111 -0
- package/dist/internal/run-client.d.ts +2 -2
- package/dist/internal/run-client.d.ts.map +1 -1
- package/dist/internal/run-client.js +38 -23
- package/dist/internal/server.d.ts.map +1 -1
- package/dist/internal/server.js +10 -4
- package/dist/internal/session-engine.d.ts +1 -1
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +21 -6
- package/dist/internal/sessions-client.d.ts +21 -0
- package/dist/internal/sessions-client.d.ts.map +1 -0
- package/dist/internal/sessions-client.js +168 -0
- package/dist/internal/stream-progress.d.ts.map +1 -1
- package/dist/internal/stream-progress.js +31 -3
- package/dist/internal/terminal-style.d.ts +22 -0
- package/dist/internal/terminal-style.d.ts.map +1 -0
- package/dist/internal/terminal-style.js +49 -0
- package/dist/internal/trajectory.d.ts +10 -5
- package/dist/internal/trajectory.d.ts.map +1 -1
- package/dist/internal/trajectory.js +82 -10
- package/dist/internal/workspace.d.ts +11 -0
- package/dist/internal/workspace.d.ts.map +1 -1
- package/dist/internal/workspace.js +38 -4
- package/dist/playground/assets/index-D-vo2lV_.css +1 -0
- package/dist/playground/assets/index-x60b9q2j.js +312 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +26 -1
- package/dist/types.d.ts.map +1 -1
- package/docs/quickstart.md +22 -7
- package/docs/reference/cli.md +51 -3
- package/package.json +3 -1
- package/skills/ab/SKILL.md +8 -8
- package/skills/create-agent/SKILL.md +28 -22
- package/skills/debug/SKILL.md +11 -11
- package/skills/evals/SKILL.md +16 -16
- package/skills/framework-map/SKILL.md +6 -6
- package/skills/github/SKILL.md +13 -13
- package/skills/hillclimb/SKILL.md +10 -10
- package/skills/setup-slack/SKILL.md +13 -13
- package/src/bin/agent-serve.ts +422 -188
- package/src/internal/chat-client.ts +252 -37
- package/src/internal/cli-ax.ts +722 -72
- package/src/internal/cli-cursor.ts +14 -42
- package/src/internal/cli-deploy.ts +428 -49
- package/src/internal/cursor/credentials.ts +14 -0
- package/src/internal/deploy-client.ts +45 -4
- package/src/internal/deploy-source.ts +133 -0
- package/src/internal/discovery.ts +53 -16
- package/src/internal/eval-run-store.ts +2 -1
- package/src/internal/eval-runner.ts +5 -0
- package/src/internal/event-mapper.ts +222 -42
- package/src/internal/init-project.ts +333 -51
- package/src/internal/install-cursor-skills.ts +327 -0
- package/src/internal/logs-client.ts +442 -0
- package/src/internal/open-browser.ts +41 -0
- package/src/internal/playground/toolchain.ts +15 -13
- package/src/internal/playground-proxy.ts +576 -0
- package/src/internal/prompt-context.ts +95 -0
- package/src/internal/request-headers.ts +23 -0
- package/src/internal/resolve-prod-target.ts +150 -0
- package/src/internal/run-client.ts +39 -36
- package/src/internal/server.ts +12 -3
- package/src/internal/session-engine.ts +22 -3
- package/src/internal/sessions-client.ts +182 -0
- package/src/internal/stream-progress.ts +36 -2
- package/src/internal/terminal-style.ts +74 -0
- package/src/internal/trajectory.ts +91 -13
- package/src/internal/workspace.ts +42 -4
- package/src/types.ts +42 -6
- package/dist/docs/assets/chunks/@localSearchIndexroot.zwQ9RCQ7.js +0 -1
- package/dist/playground/assets/index-B1Qc9h2u.css +0 -1
- package/dist/playground/assets/index-CpDYCj8W.js +0 -79
- /package/dist/docs/assets/{quickstart.md.CfU8_uTC.lean.js → quickstart.md.BU6Iwi_9.lean.js} +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a hosted (managed) agent-serve deployment into a base URL +
|
|
3
|
+
* request headers for chat/run/call/eval `--prod`.
|
|
4
|
+
*
|
|
5
|
+
* Uses short-lived `engineAccess` from the deployment status route
|
|
6
|
+
* (Cursor API key on the management API; `X-Anyrun-Port-Token` on the
|
|
7
|
+
* engine). Alias tokens are out of scope here.
|
|
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 { basename, resolve } from "node:path";
|
|
19
|
+
import { resolveDeployAuth } from "./cli-deploy.js";
|
|
20
|
+
import { DeployApiError, slugFromDirectoryName, validateDeploymentSlug, } from "./deploy-client.js";
|
|
21
|
+
import { CLI_COMMAND_NAME as CLI } from "./distribution.js";
|
|
22
|
+
import { stderrPalette } from "./terminal-style.js";
|
|
23
|
+
/**
|
|
24
|
+
* Interactive CLI keep-alive for hosted engines. Without these, a hibernated
|
|
25
|
+
* Anyrun pod returns 417 `pod_hibernated` and never wakes. Matches the
|
|
26
|
+
* cloud-agent interactive keep-alive shape (lower ≤ upper, seconds).
|
|
27
|
+
*/
|
|
28
|
+
export const PROD_ENGINE_WAKE_HEADERS = {
|
|
29
|
+
"x-anyrun-hibernation-lower-bound-s": "1800",
|
|
30
|
+
"x-anyrun-hibernation-upper-bound-s": "3600",
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Look up a running deployment and return its engineAccess URL/headers.
|
|
34
|
+
* Throws {@link Error} with a CLI-ready message on failure.
|
|
35
|
+
*/
|
|
36
|
+
export function resolveProdTarget(options) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
var _a;
|
|
39
|
+
const err = (_a = options.err) !== null && _a !== void 0 ? _a : ((text) => void process.stderr.write(text));
|
|
40
|
+
const slug = resolveProdSlug(options);
|
|
41
|
+
const auth = yield resolveDeployAuth({
|
|
42
|
+
team: options.team,
|
|
43
|
+
apiKey: options.apiKey,
|
|
44
|
+
fetchImpl: options.fetchImpl,
|
|
45
|
+
err,
|
|
46
|
+
});
|
|
47
|
+
if (typeof auth === "number") {
|
|
48
|
+
throw new Error(`Could not resolve Cursor credentials/team for --prod (see above).`);
|
|
49
|
+
}
|
|
50
|
+
let detail;
|
|
51
|
+
try {
|
|
52
|
+
detail = yield auth.client.getDeployment({
|
|
53
|
+
teamId: auth.teamId,
|
|
54
|
+
slug,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof DeployApiError) {
|
|
59
|
+
throw new Error(`Deployment "${slug}" (team ${auth.teamId}): ${error.message}`);
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
// `degraded` still serves the previous ACTIVE engine; allow runtime access
|
|
64
|
+
// when the control plane minted engineAccess for it.
|
|
65
|
+
const access = detail.engineAccess;
|
|
66
|
+
const statusOk = detail.status === "running" || detail.status === "degraded";
|
|
67
|
+
if (!statusOk) {
|
|
68
|
+
const lastError = detail.lastError === null || detail.lastError === undefined
|
|
69
|
+
? ""
|
|
70
|
+
: ` ${sanitizeCustomerFacingDetail(detail.lastError)}`;
|
|
71
|
+
throw new Error(`Deployment "${slug}" is ${detail.status}, not running.${lastError}\n` +
|
|
72
|
+
`Deploy or wait: \`${CLI} deploy --slug ${slug}\` / \`${CLI} deployment ${slug}\``);
|
|
73
|
+
}
|
|
74
|
+
if (access === null || access === undefined) {
|
|
75
|
+
throw new Error(`Deployment "${slug}" is ${detail.status} but is not reachable yet. ` +
|
|
76
|
+
`Try \`${CLI} deployment ${slug}\` or redeploy.`);
|
|
77
|
+
}
|
|
78
|
+
err(`${stderrPalette().dim(`Using hosted deployment "${slug}".`)}\n`);
|
|
79
|
+
return {
|
|
80
|
+
agentUrl: access.url.replace(/\/$/, ""),
|
|
81
|
+
headers: Object.assign(Object.assign({}, access.headers), PROD_ENGINE_WAKE_HEADERS),
|
|
82
|
+
slug,
|
|
83
|
+
expiresAt: access.expiresAt,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** Strip obvious hosting internals from customer-facing error fragments. */
|
|
88
|
+
function sanitizeCustomerFacingDetail(message) {
|
|
89
|
+
return message
|
|
90
|
+
.replace(/https?:\/\/\S+/gi, "[url]")
|
|
91
|
+
.replace(/\bpod-[a-z0-9]+\b/gi, "[runtime]")
|
|
92
|
+
.replace(/\banyrun\b/gi, "runtime")
|
|
93
|
+
.replace(/\bcursorvm\.com\b/gi, "host");
|
|
94
|
+
}
|
|
95
|
+
/** Resolve the deployment slug the same way `deploy` does for a single dir. */
|
|
96
|
+
export function resolveProdSlug(options) {
|
|
97
|
+
var _a;
|
|
98
|
+
if (options.slug !== undefined && options.slug !== "") {
|
|
99
|
+
const slugError = validateDeploymentSlug(options.slug);
|
|
100
|
+
if (slugError !== undefined) {
|
|
101
|
+
throw new Error(slugError);
|
|
102
|
+
}
|
|
103
|
+
return options.slug;
|
|
104
|
+
}
|
|
105
|
+
const dir = resolve((_a = options.cwd) !== null && _a !== void 0 ? _a : process.cwd(), options.dir);
|
|
106
|
+
const derived = slugFromDirectoryName(basename(dir));
|
|
107
|
+
if (derived === undefined) {
|
|
108
|
+
throw new Error(`Could not derive a deployment slug from the directory name ${JSON.stringify(basename(dir))}; pass --slug.`);
|
|
109
|
+
}
|
|
110
|
+
return derived;
|
|
111
|
+
}
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* compact {@link Trajectory} plus the continuation token for follow-ups.
|
|
7
7
|
*/
|
|
8
8
|
import type { SessionEvent, SessionPurpose } from "../types.js";
|
|
9
|
+
import { type RequestAuth } from "./request-headers.js";
|
|
9
10
|
import { type Trajectory } from "./trajectory.js";
|
|
10
11
|
/** Thrown when a turn stream exceeds `timeoutMs`; carries the session id. */
|
|
11
12
|
export declare class RunSessionTimeoutError extends Error {
|
|
12
13
|
readonly sessionId: string;
|
|
13
14
|
constructor(message: string, sessionId: string);
|
|
14
15
|
}
|
|
15
|
-
export interface RunClientOptions {
|
|
16
|
+
export interface RunClientOptions extends RequestAuth {
|
|
16
17
|
baseUrl: string;
|
|
17
|
-
bearerToken?: string;
|
|
18
18
|
/** Abort a hung turn. */
|
|
19
19
|
timeoutMs?: number;
|
|
20
20
|
/** Called for each stream event as it arrives (for CLI progress). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-client.d.ts","sourceRoot":"","sources":["../../src/internal/run-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEnE,6EAA6E;AAC7E,qBAAa,sBA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AM,CAAC;IAC3B,gEAAgE;IAChE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC,GACA,OAAO,CAAC,gBAAgB,CAAC,CAuD3B"}
|
|
@@ -14,6 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
+
import { mergeRequestHeaders } from "./request-headers.js";
|
|
17
18
|
import { buildTrajectory } from "./trajectory.js";
|
|
18
19
|
/** Thrown when a turn stream exceeds `timeoutMs`; carries the session id. */
|
|
19
20
|
export class RunSessionTimeoutError extends Error {
|
|
@@ -42,17 +43,24 @@ export function runSession(options) {
|
|
|
42
43
|
let continuationToken = options.continuationToken;
|
|
43
44
|
const allEvents = [];
|
|
44
45
|
let nextEventIndex = 0;
|
|
46
|
+
const auth = {
|
|
47
|
+
bearerToken: options.bearerToken,
|
|
48
|
+
headers: options.headers,
|
|
49
|
+
};
|
|
45
50
|
for (const message of options.messages) {
|
|
46
|
-
const turn = yield runOneTurn(
|
|
51
|
+
const turn = yield runOneTurn({
|
|
52
|
+
baseUrl,
|
|
47
53
|
message,
|
|
48
54
|
sessionId,
|
|
49
|
-
continuationToken,
|
|
50
|
-
?
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
:
|
|
54
|
-
|
|
55
|
-
:
|
|
55
|
+
continuationToken,
|
|
56
|
+
startIndex: sessionId === undefined ? 0 : nextEventIndex,
|
|
57
|
+
auth,
|
|
58
|
+
timeoutMs: options.timeoutMs,
|
|
59
|
+
onEvent: options.onEvent,
|
|
60
|
+
purpose: sessionId === undefined ? options.purpose : undefined,
|
|
61
|
+
workspaceDir: sessionId === undefined ? options.workspaceDir : undefined,
|
|
62
|
+
workspaceFiles: sessionId === undefined ? options.workspaceFiles : undefined,
|
|
63
|
+
});
|
|
56
64
|
sessionId = turn.sessionId;
|
|
57
65
|
continuationToken = turn.continuationToken;
|
|
58
66
|
allEvents.push(...turn.events);
|
|
@@ -77,11 +85,17 @@ function runOneTurn(args) {
|
|
|
77
85
|
let sessionId = args.sessionId;
|
|
78
86
|
let continuationToken = args.continuationToken;
|
|
79
87
|
if (sessionId === undefined) {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
const body = { message: args.message };
|
|
89
|
+
if (args.purpose !== undefined) {
|
|
90
|
+
body.purpose = args.purpose;
|
|
91
|
+
}
|
|
92
|
+
if (args.workspaceDir !== undefined) {
|
|
93
|
+
body.workspaceDir = args.workspaceDir;
|
|
94
|
+
}
|
|
95
|
+
if (args.workspaceFiles !== undefined) {
|
|
96
|
+
body.workspaceFiles = args.workspaceFiles;
|
|
97
|
+
}
|
|
98
|
+
const created = yield postJson(args.baseUrl, "/v1/session", body, args.auth);
|
|
85
99
|
if (created.status >= 400 || created.body.ok === false) {
|
|
86
100
|
throw new Error(`POST /v1/session failed: ${(_a = str(created.body.error)) !== null && _a !== void 0 ? _a : created.status} ${(_b = str(created.body.message)) !== null && _b !== void 0 ? _b : ""}`.trim());
|
|
87
101
|
}
|
|
@@ -89,7 +103,7 @@ function runOneTurn(args) {
|
|
|
89
103
|
continuationToken = str(created.body.continuationToken);
|
|
90
104
|
}
|
|
91
105
|
else {
|
|
92
|
-
const resp = yield postJson(args.baseUrl, `/v1/session/${sessionId}`, { message: args.message, continuationToken }, args.
|
|
106
|
+
const resp = yield postJson(args.baseUrl, `/v1/session/${sessionId}`, { message: args.message, continuationToken }, args.auth);
|
|
93
107
|
if (resp.status >= 400 || resp.body.ok === false) {
|
|
94
108
|
throw new Error(`follow-up failed: ${(_c = str(resp.body.error)) !== null && _c !== void 0 ? _c : resp.status}: ${(_d = str(resp.body.message)) !== null && _d !== void 0 ? _d : ""}`.trim());
|
|
95
109
|
}
|
|
@@ -102,7 +116,7 @@ function runOneTurn(args) {
|
|
|
102
116
|
baseUrl: args.baseUrl,
|
|
103
117
|
sessionId,
|
|
104
118
|
startIndex: args.startIndex,
|
|
105
|
-
|
|
119
|
+
auth: args.auth,
|
|
106
120
|
timeoutMs: args.timeoutMs,
|
|
107
121
|
onEvent: args.onEvent,
|
|
108
122
|
});
|
|
@@ -121,7 +135,7 @@ function collectStream(args) {
|
|
|
121
135
|
: setTimeout(() => controller.abort(), args.timeoutMs);
|
|
122
136
|
try {
|
|
123
137
|
const resp = yield fetch(`${args.baseUrl}/v1/session/${args.sessionId}/stream?startIndex=${args.startIndex}`, {
|
|
124
|
-
headers:
|
|
138
|
+
headers: mergeRequestHeaders(args.auth),
|
|
125
139
|
signal: controller.signal,
|
|
126
140
|
});
|
|
127
141
|
if (!resp.ok || resp.body === null) {
|
|
@@ -178,16 +192,11 @@ function collectStream(args) {
|
|
|
178
192
|
}
|
|
179
193
|
});
|
|
180
194
|
}
|
|
181
|
-
function
|
|
182
|
-
return bearerToken === undefined
|
|
183
|
-
? {}
|
|
184
|
-
: { authorization: `Bearer ${bearerToken}` };
|
|
185
|
-
}
|
|
186
|
-
function postJson(baseUrl, path, body, bearerToken) {
|
|
195
|
+
function postJson(baseUrl, path, body, auth) {
|
|
187
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
197
|
const resp = yield fetch(`${baseUrl}${path}`, {
|
|
189
198
|
method: "POST",
|
|
190
|
-
headers: Object.assign({ "content-type": "application/json" },
|
|
199
|
+
headers: Object.assign({ "content-type": "application/json" }, mergeRequestHeaders(auth)),
|
|
191
200
|
body: JSON.stringify(body),
|
|
192
201
|
});
|
|
193
202
|
const text = yield resp.text();
|
|
@@ -200,6 +209,12 @@ function postJson(baseUrl, path, body, bearerToken) {
|
|
|
200
209
|
parsed = { message: text };
|
|
201
210
|
}
|
|
202
211
|
}
|
|
212
|
+
const anyrunReason = resp.headers.get("x-anyrun-failure-reason");
|
|
213
|
+
if (anyrunReason !== null &&
|
|
214
|
+
anyrunReason !== "" &&
|
|
215
|
+
(parsed.message === undefined || parsed.message === "")) {
|
|
216
|
+
parsed.message = anyrunReason;
|
|
217
|
+
}
|
|
203
218
|
return { status: resp.status, body: parsed };
|
|
204
219
|
});
|
|
205
220
|
}
|
|
@@ -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;
|
|
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"}
|
package/dist/internal/server.js
CHANGED
|
@@ -42,7 +42,7 @@ import { assertSlackCursorAgentName } from "../channels/slack/types.js";
|
|
|
42
42
|
import { allowAll, bearerAuth, localDevStrict } from "../channels.js";
|
|
43
43
|
import { CursorAccountMcpBridge, collectCursorAccountConnections, cursorAccountMcpPath, } from "./cursor/account-mcp.js";
|
|
44
44
|
import { CursorBackendClient } from "./cursor/backend-client.js";
|
|
45
|
-
import { cursorBackendUrl, resolveApiKey, SIGN_IN_HINT, } from "./cursor/credentials.js";
|
|
45
|
+
import { cursorBackendUrl, cursorExternalApiUrl, resolveApiKey, SIGN_IN_HINT, } from "./cursor/credentials.js";
|
|
46
46
|
import { CursorGithubCredentialProvider } from "./cursor/github-credentials.js";
|
|
47
47
|
import { CursorEventRelay, formatCursorScmEventLog, scmMetadataToGitHubPayload, } from "./cursor-event-relay.js";
|
|
48
48
|
import { CursorSlackRelay, createCursorSlackApiCaller, formatCursorSlackEventLog, } from "./cursor-slack-relay.js";
|
|
@@ -120,7 +120,10 @@ export function startServer(mounts_1) {
|
|
|
120
120
|
throw new Error("githubChannel({ cursorAccount: true }) could not resolve Cursor event authentication.");
|
|
121
121
|
}
|
|
122
122
|
if (options.allowAnonymous === true) {
|
|
123
|
-
|
|
123
|
+
if (options.allowAnonymousCursorGithub !== true) {
|
|
124
|
+
throw new Error("githubChannel({ cursorAccount: true }) cannot be served with --allow-anonymous because admitted callers could use the signed-in account's GitHub access. If every admitted caller is trusted (e.g. behind an SSO proxy), opt in with --allow-anonymous-cursor-github.");
|
|
125
|
+
}
|
|
126
|
+
logger("[agent-serve] warning: --allow-anonymous-cursor-github — every admitted HTTP caller can drive sessions holding the signed-in account's repo-scoped GitHub credential; serve this only behind a trusted boundary (e.g. an SSO proxy)");
|
|
124
127
|
}
|
|
125
128
|
if (cursorGithubConfig.scope.permissions === "contents-write") {
|
|
126
129
|
logger('[agent-serve] warning: Cursor GitHub credentials include contents:write — the host holds a push-capable token shared with model-driven tools and untrusted webhook content; prefer permissions: "pr-write" unless this agent must push code');
|
|
@@ -1037,14 +1040,17 @@ function mountAgentRoutes(router, runtime, args) {
|
|
|
1037
1040
|
* serve instead of starting with a relay that could never run.
|
|
1038
1041
|
*/
|
|
1039
1042
|
function requireCursorEventsAuth(config, accountKey) {
|
|
1040
|
-
var _a, _b, _c
|
|
1043
|
+
var _a, _b, _c;
|
|
1041
1044
|
const apiKey = ((_b = (_a = config.apiKey) !== null && _a !== void 0 ? _a : accountKey === null || accountKey === void 0 ? void 0 : accountKey.apiKey) !== null && _b !== void 0 ? _b : "").trim();
|
|
1042
1045
|
if (apiKey === "") {
|
|
1043
1046
|
throw new Error(`[agent-serve] --cursor-events (serve({ cursorEvents })) requires a signed-in Cursor account: the SCM event stream is read as the host's user. ${SIGN_IN_HINT}`);
|
|
1044
1047
|
}
|
|
1045
1048
|
return {
|
|
1046
1049
|
apiKey,
|
|
1047
|
-
|
|
1050
|
+
// `/v0/scm-events/*` lives on the external API (api.cursor.com), not
|
|
1051
|
+
// api2. Prefer that default over the account key's backendUrl, which
|
|
1052
|
+
// follows cursorBackendUrl() (api2) when CURSOR_API_KEY is set.
|
|
1053
|
+
baseUrl: (_c = config.baseUrl) !== null && _c !== void 0 ? _c : cursorExternalApiUrl(),
|
|
1048
1054
|
};
|
|
1049
1055
|
}
|
|
1050
1056
|
/**
|
|
@@ -13,7 +13,7 @@ import type { AgentRunner } from "./sdk-runner.js";
|
|
|
13
13
|
import { SessionStore } from "./session-store.js";
|
|
14
14
|
import { StorageCoordinator } from "./storage-coordinator.js";
|
|
15
15
|
export declare const HTTP_CHANNEL_ID = "http";
|
|
16
|
-
export
|
|
16
|
+
export { SCHEDULE_CHANNEL_PREFIX } from "./prompt-context.js";
|
|
17
17
|
export declare class SessionBusyError extends Error {
|
|
18
18
|
constructor(sessionId: string);
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-engine.d.ts","sourceRoot":"","sources":["../../src/internal/session-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAEtB,KAAK,cAAc,EAInB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAG1B,KAAK,eAAe,EACpB,KAAK,YAAY,EAIjB,KAAK,kBAAkB,EACvB,KAAK,YAAY,E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E,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GACjC,OAAO,CAAC,UAAU,CAAC,CA0DrB;IAEK,WAAW,CACf,SAAS,EAAE,MAAM,EACjB,UAAU,SAAI,GACb,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAGrC;IAED;;;;OAIG;IACG,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoCzE;IAED,kEAAkE;IAC5D,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,SAAI,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAG3E;IAEK,oBAAoB,CACxB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,OAAO,CAAC,IAAI,CAAC,CAKf;IAED,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAIxC;IAED,WAAW,CAAC,MAAM,EAAE,aAAa,GAAG,WAAW,CAc9C;IAED,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,gBAAgB;IAwBxB,OAAO,CAAC,mBAAmB;IAc3B,sEAAsE;IACtE,OAAO,CAAC,YAAY;IA6BpB;;;;;;;;;;;OAWG;IACG,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAgB3C;YAEa,cAAc;IA4F5B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,4BAA4B;YAqBtB,gCAAgC;IAyB9C;;;;;OAKG;YACW,kBAAkB;IAYhC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAO/C;IAED,yEAAyE;IACnE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAU3B;CACF"}
|
|
@@ -37,19 +37,21 @@ import { buildABSnapshot } from "./ab-snapshot.js";
|
|
|
37
37
|
import { ApprovalGate } from "./approval-gate.js";
|
|
38
38
|
import { samePrincipal } from "./auth.js";
|
|
39
39
|
import { mergeCloudOptions, resolveSessionRuntime } from "./cloud-merge.js";
|
|
40
|
+
import { isDevMode } from "./dev-mode.js";
|
|
40
41
|
import { EventLogStore } from "./event-log.js";
|
|
41
42
|
import { TurnEventMapper } from "./event-mapper.js";
|
|
42
43
|
import { createHostPlatforms } from "./host-platforms.js";
|
|
43
44
|
import { formatContinuationToken, newContinuationKey, newSessionId, newToolCallId, } from "./ids.js";
|
|
44
45
|
import { validateToolInput } from "./json-schema.js";
|
|
45
46
|
import { McpHost } from "./mcp-host.js";
|
|
47
|
+
import { buildIdentitySection, buildSessionContextBlock, SCHEDULE_CHANNEL_PREFIX, } from "./prompt-context.js";
|
|
46
48
|
import { assertCloudCanHonorAccountServersFilters } from "./resolved-connections.js";
|
|
47
49
|
import { SessionStore } from "./session-store.js";
|
|
48
50
|
import { StorageCoordinator } from "./storage-coordinator.js";
|
|
49
51
|
import { normalizeToolResult, toolCallErrorMessage } from "./tool-result.js";
|
|
50
52
|
import { buildAgentToolsCatalog, materializeWorkspace, writeWorkspaceFiles, } from "./workspace.js";
|
|
51
53
|
export const HTTP_CHANNEL_ID = "http";
|
|
52
|
-
export
|
|
54
|
+
export { SCHEDULE_CHANNEL_PREFIX } from "./prompt-context.js";
|
|
53
55
|
export class SessionBusyError extends Error {
|
|
54
56
|
constructor(sessionId) {
|
|
55
57
|
super(`Session ${sessionId} already has a running turn; wait for session.waiting before sending a follow-up`);
|
|
@@ -537,7 +539,10 @@ export class SessionEngine {
|
|
|
537
539
|
// Yield so the HTTP NDJSON writer can flush tool start/result
|
|
538
540
|
// events while sibling parallel tools are still executing.
|
|
539
541
|
if (update.type === "tool-call-started" ||
|
|
540
|
-
update.type === "tool-call-completed"
|
|
542
|
+
update.type === "tool-call-completed" ||
|
|
543
|
+
// Nested subagent progress (newer SDKs); string check keeps
|
|
544
|
+
// typecheck green against older published `@cursor/sdk` pins.
|
|
545
|
+
update.type === "tool-call-delta") {
|
|
541
546
|
yield yieldEventLoop();
|
|
542
547
|
}
|
|
543
548
|
}), signal);
|
|
@@ -601,8 +606,8 @@ export class SessionEngine {
|
|
|
601
606
|
});
|
|
602
607
|
}
|
|
603
608
|
buildTurnRequest(record, agent, turnId, prompt, isFirstTurn, emit, onUpdate, signal) {
|
|
604
|
-
var _a;
|
|
605
|
-
var
|
|
609
|
+
var _a, _b, _c;
|
|
610
|
+
var _d;
|
|
606
611
|
// Per-session cloud attach (channel/tool handoff) forces cloud runtime
|
|
607
612
|
// even when the agent defaults to local for chat server tools.
|
|
608
613
|
const runtime = resolveSessionRuntime({
|
|
@@ -616,14 +621,24 @@ export class SessionEngine {
|
|
|
616
621
|
})
|
|
617
622
|
: undefined;
|
|
618
623
|
let turnPrompt = prompt;
|
|
624
|
+
if (isFirstTurn) {
|
|
625
|
+
const contextBlock = buildSessionContextBlock({
|
|
626
|
+
sessionId: record.sessionId,
|
|
627
|
+
channelId: record.channelId,
|
|
628
|
+
channelKind: (_b = (_a = this.channelsById.get(record.channelId)) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.kind,
|
|
629
|
+
environment: isDevMode() ? "local dev server" : "hosted deployment",
|
|
630
|
+
});
|
|
631
|
+
turnPrompt = `${contextBlock}\n\n${prompt}`;
|
|
632
|
+
}
|
|
619
633
|
if (runtime === "cloud" && isFirstTurn) {
|
|
620
634
|
const preamble = [
|
|
621
|
-
(
|
|
635
|
+
(_d = (_c = agent.instructions) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : "",
|
|
636
|
+
buildIdentitySection(agent),
|
|
622
637
|
buildAgentToolsCatalog(agent.tools, { includeScripts: true }),
|
|
623
638
|
]
|
|
624
639
|
.filter((part) => part !== "")
|
|
625
640
|
.join("\n\n");
|
|
626
|
-
turnPrompt =
|
|
641
|
+
turnPrompt = `${preamble}\n\n${turnPrompt}`;
|
|
627
642
|
}
|
|
628
643
|
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ sessionId: record.sessionId }, (record.sdkAgentId === undefined
|
|
629
644
|
? {}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session list / event fetch for CLI (`sessions`, `session`, chat reattach).
|
|
3
|
+
*
|
|
4
|
+
* Customer-facing errors never include hosting URLs or infra jargon.
|
|
5
|
+
*/
|
|
6
|
+
import type { SessionEvent, SessionSummary } from "../types.js";
|
|
7
|
+
import { type RequestAuth } from "./request-headers.js";
|
|
8
|
+
export declare function listSessions(args: {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
auth?: RequestAuth;
|
|
11
|
+
fetchImpl?: typeof fetch;
|
|
12
|
+
}): Promise<SessionSummary[]>;
|
|
13
|
+
export declare function fetchSessionEvents(args: {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
auth?: RequestAuth;
|
|
17
|
+
fetchImpl?: typeof fetch;
|
|
18
|
+
}): Promise<SessionEvent[]>;
|
|
19
|
+
/** Format a sessions table (id, channel, mode, turns, running, updated). */
|
|
20
|
+
export declare function formatSessionsTable(sessions: SessionSummary[]): string;
|
|
21
|
+
//# sourceMappingURL=sessions-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions-client.d.ts","sourceRoot":"","sources":["../../src/internal/sessions-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE7E,wBAAsB,YAAY,CAAC,IAAI,EAAE;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CA8B5B;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAuE1B;AAgCD,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,MAAM,CActE"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session list / event fetch for CLI (`sessions`, `session`, chat reattach).
|
|
3
|
+
*
|
|
4
|
+
* Customer-facing errors never include hosting URLs or infra jargon.
|
|
5
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
import { sanitizeCustomerError } from "./logs-client.js";
|
|
16
|
+
import { mergeRequestHeaders } from "./request-headers.js";
|
|
17
|
+
export function listSessions(args) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
20
|
+
const baseUrl = args.baseUrl.replace(/\/$/, "");
|
|
21
|
+
const fetchImpl = (_a = args.fetchImpl) !== null && _a !== void 0 ? _a : fetch;
|
|
22
|
+
let resp;
|
|
23
|
+
try {
|
|
24
|
+
resp = yield fetchImpl(`${baseUrl}/v1/sessions`, {
|
|
25
|
+
headers: mergeRequestHeaders(args.auth),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error(sanitizeCustomerError(error instanceof Error ? error.message : "Could not list sessions."));
|
|
30
|
+
}
|
|
31
|
+
if (!resp.ok) {
|
|
32
|
+
throw new Error(`Could not list sessions (HTTP ${resp.status}).`);
|
|
33
|
+
}
|
|
34
|
+
const body = (yield resp.json());
|
|
35
|
+
if (!Array.isArray(body.sessions)) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const row of body.sessions) {
|
|
40
|
+
const parsed = parseSessionSummary(row);
|
|
41
|
+
if (parsed !== undefined) {
|
|
42
|
+
out.push(parsed);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export function fetchSessionEvents(args) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
var _a;
|
|
51
|
+
const baseUrl = args.baseUrl.replace(/\/$/, "");
|
|
52
|
+
const fetchImpl = (_a = args.fetchImpl) !== null && _a !== void 0 ? _a : fetch;
|
|
53
|
+
const path = `/v1/session/${encodeURIComponent(args.sessionId)}/events`;
|
|
54
|
+
try {
|
|
55
|
+
const jsonResp = yield fetchImpl(`${baseUrl}${path}?format=json`, {
|
|
56
|
+
headers: mergeRequestHeaders(args.auth),
|
|
57
|
+
});
|
|
58
|
+
if (jsonResp.ok) {
|
|
59
|
+
const body = (yield jsonResp.json());
|
|
60
|
+
if (Array.isArray(body.events)) {
|
|
61
|
+
return body.events;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (jsonResp.status === 404) {
|
|
65
|
+
throw new Error(`Session ${args.sessionId} not found.`);
|
|
66
|
+
}
|
|
67
|
+
else if (jsonResp.status === 403) {
|
|
68
|
+
throw new Error(`Session ${args.sessionId} is not readable by this caller.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (error instanceof Error && error.message.startsWith("Session ")) {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
// Fall through to NDJSON.
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const resp = yield fetchImpl(`${baseUrl}${path}`, {
|
|
79
|
+
headers: mergeRequestHeaders(args.auth),
|
|
80
|
+
});
|
|
81
|
+
if (resp.status === 404) {
|
|
82
|
+
throw new Error(`Session ${args.sessionId} not found.`);
|
|
83
|
+
}
|
|
84
|
+
if (resp.status === 403) {
|
|
85
|
+
throw new Error(`Session ${args.sessionId} is not readable by this caller.`);
|
|
86
|
+
}
|
|
87
|
+
if (!resp.ok) {
|
|
88
|
+
throw new Error(`Could not fetch session events (HTTP ${resp.status}).`);
|
|
89
|
+
}
|
|
90
|
+
const text = yield resp.text();
|
|
91
|
+
const events = [];
|
|
92
|
+
for (const line of text.split("\n")) {
|
|
93
|
+
if (line.trim() === "") {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
events.push(JSON.parse(line));
|
|
98
|
+
}
|
|
99
|
+
catch (_b) {
|
|
100
|
+
// skip malformed lines
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return events;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error instanceof Error && error.message.startsWith("Session ")) {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
if (error instanceof Error && error.message.startsWith("Could not fetch")) {
|
|
110
|
+
throw new Error(sanitizeCustomerError(error.message));
|
|
111
|
+
}
|
|
112
|
+
throw new Error(sanitizeCustomerError(error instanceof Error
|
|
113
|
+
? error.message
|
|
114
|
+
: "Could not fetch session events."));
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Lenient parse so partial stubs / older servers still list by sessionId. */
|
|
119
|
+
function parseSessionSummary(value) {
|
|
120
|
+
if (typeof value !== "object" || value === null) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
const row = value;
|
|
124
|
+
if (typeof row.sessionId !== "string" || row.sessionId === "") {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
const continuationToken = typeof row.continuationToken === "string"
|
|
128
|
+
? row.continuationToken
|
|
129
|
+
: row.continuationToken === null
|
|
130
|
+
? null
|
|
131
|
+
: null;
|
|
132
|
+
return {
|
|
133
|
+
sessionId: row.sessionId,
|
|
134
|
+
channelId: typeof row.channelId === "string" ? row.channelId : "",
|
|
135
|
+
mode: row.mode === "task" ? "task" : "chat",
|
|
136
|
+
title: typeof row.title === "string" ? row.title : undefined,
|
|
137
|
+
turnCount: typeof row.turnCount === "number" ? row.turnCount : 0,
|
|
138
|
+
running: row.running === true,
|
|
139
|
+
createdAt: typeof row.createdAt === "string" ? row.createdAt : "",
|
|
140
|
+
updatedAt: typeof row.updatedAt === "string" ? row.updatedAt : "",
|
|
141
|
+
continuationToken,
|
|
142
|
+
externalUrl: typeof row.externalUrl === "string" ? row.externalUrl : undefined,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** Format a sessions table (id, channel, mode, turns, running, updated). */
|
|
146
|
+
export function formatSessionsTable(sessions) {
|
|
147
|
+
if (sessions.length === 0) {
|
|
148
|
+
return "No sessions.\n";
|
|
149
|
+
}
|
|
150
|
+
const header = ["SESSION", "CHANNEL", "MODE", "TURNS", "RUNNING", "UPDATED"];
|
|
151
|
+
const rows = sessions.map((s) => [
|
|
152
|
+
s.sessionId,
|
|
153
|
+
s.channelId,
|
|
154
|
+
s.mode,
|
|
155
|
+
String(s.turnCount),
|
|
156
|
+
s.running ? "yes" : "no",
|
|
157
|
+
s.updatedAt,
|
|
158
|
+
]);
|
|
159
|
+
return `${renderTable(header, rows)}\n`;
|
|
160
|
+
}
|
|
161
|
+
function renderTable(header, rows) {
|
|
162
|
+
const widths = header.map((h, i) => Math.max(h.length, ...rows.map((row) => { var _a; return ((_a = row[i]) !== null && _a !== void 0 ? _a : "").length; })));
|
|
163
|
+
const renderRow = (row) => row
|
|
164
|
+
.map((cell, i) => { var _a; return cell.padEnd((_a = widths[i]) !== null && _a !== void 0 ? _a : 0); })
|
|
165
|
+
.join(" ")
|
|
166
|
+
.trimEnd();
|
|
167
|
+
return [renderRow(header), ...rows.map(renderRow)].join("\n");
|
|
168
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-progress.d.ts","sourceRoot":"","sources":["../../src/internal/stream-progress.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,KAAK,IAAI,IAAI,CAAC;CACf;AAED,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE;IAC7C,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"stream-progress.d.ts","sourceRoot":"","sources":["../../src/internal/stream-progress.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,KAAK,IAAI,IAAI,CAAC;CACf;AAED,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE;IAC7C,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,cAAc,CAqNjB"}
|