@cursor/july 0.1.95 → 0.1.96
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 +3 -4
- package/dist/channels/deployments/types.d.ts +1 -1
- package/dist/channels/deployments/types.d.ts.map +1 -1
- package/dist/channels/deployments/types.js +1 -0
- package/dist/channels/origin/api.d.ts +59 -13
- package/dist/channels/origin/api.d.ts.map +1 -1
- package/dist/channels/origin/api.js +168 -27
- package/dist/channels/origin/binding.d.ts +2 -2
- package/dist/channels/origin/checks.d.ts +6 -6
- package/dist/channels/origin/checks.js +6 -6
- package/dist/channels/origin/cursor-account.d.ts +5 -3
- package/dist/channels/origin/cursor-account.d.ts.map +1 -1
- package/dist/channels/origin/cursor-account.js +5 -3
- package/dist/channels/slack/api.d.ts +9 -0
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +36 -5
- package/dist/channels/slack/defaults.d.ts.map +1 -1
- package/dist/channels/slack/defaults.js +17 -46
- package/dist/channels/slack/dispatch.d.ts +7 -1
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +47 -23
- package/dist/channels/slack/inbound.d.ts +8 -0
- package/dist/channels/slack/inbound.d.ts.map +1 -1
- package/dist/channels/slack/inbound.js +32 -0
- package/dist/channels/slack/live-delivery.d.ts +26 -29
- package/dist/channels/slack/live-delivery.d.ts.map +1 -1
- package/dist/channels/slack/live-delivery.js +172 -73
- package/dist/channels/slack/manifest.d.ts.map +1 -1
- package/dist/channels/slack/manifest.js +5 -1
- package/dist/channels/slack/nudge-carrier.d.ts +2 -0
- package/dist/channels/slack/nudge-carrier.d.ts.map +1 -1
- package/dist/channels/slack/nudge-carrier.js +48 -1
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +2 -2
- package/dist/docs/404.html +2 -2
- package/dist/docs/ab.html +4 -4
- package/dist/docs/assets/{app.BBj0klBO.js → app.jXleCmOc.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DFoGuETX.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.CUEXpL78.js → VPLocalSearchBox.8LhyglIT.js} +1 -1
- package/dist/docs/assets/chunks/{theme.DabmQnia.js → theme.9ged-pr2.js} +2 -2
- package/dist/docs/assets/index.md.CI93Ltlb.js +5 -0
- package/dist/docs/assets/{index.md.BoHaMdeZ.lean.js → index.md.CI93Ltlb.lean.js} +1 -1
- package/dist/docs/assets/{reference_cli.md.BsMOxDvh.js → reference_cli.md.CCnG-nJx.js} +2 -1
- package/dist/docs/assets/templates_code-wiki.md.CDYZIBFN.js +2 -0
- package/dist/docs/assets/templates_code-wiki.md.CDYZIBFN.lean.js +1 -0
- package/dist/docs/building-with-agents.html +4 -4
- package/dist/docs/concepts.html +4 -4
- package/dist/docs/deployment.html +4 -4
- package/dist/docs/evals.html +4 -4
- package/dist/docs/guides/agent-to-agent.html +4 -4
- package/dist/docs/guides/cloud-runtime.html +4 -4
- package/dist/docs/guides/convert-automation.html +4 -4
- package/dist/docs/guides/github.html +4 -4
- package/dist/docs/guides/human-in-the-loop.html +4 -4
- package/dist/docs/guides/mcp-oauth.html +4 -4
- package/dist/docs/guides/opentelemetry.html +4 -4
- package/dist/docs/guides/slack.html +4 -4
- package/dist/docs/guides/webhooks.html +4 -4
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +4 -4
- package/dist/docs/index.html +6 -6
- package/dist/docs/index.md +3 -1
- package/dist/docs/llms-full.txt +102 -3
- package/dist/docs/llms.txt +1 -0
- package/dist/docs/quickstart.html +4 -4
- package/dist/docs/reference/agent-config.html +4 -4
- package/dist/docs/reference/artifacts.html +4 -4
- package/dist/docs/reference/channels.html +4 -4
- package/dist/docs/reference/cli.html +7 -6
- package/dist/docs/reference/cli.md +3 -2
- package/dist/docs/reference/connections.html +4 -4
- package/dist/docs/reference/hooks.html +4 -4
- package/dist/docs/reference/http-api.html +4 -4
- package/dist/docs/reference/instructions.html +4 -4
- package/dist/docs/reference/playground.html +4 -4
- package/dist/docs/reference/project-layout.html +4 -4
- package/dist/docs/reference/prompt.html +4 -4
- package/dist/docs/reference/schedules.html +4 -4
- package/dist/docs/reference/sessions.html +4 -4
- package/dist/docs/reference/skills.html +4 -4
- package/dist/docs/reference/subagents.html +4 -4
- package/dist/docs/reference/tools.html +4 -4
- package/dist/docs/scaffolding-agents.html +4 -4
- package/dist/docs/storage.html +4 -4
- package/dist/docs/templates/agentic-owners.html +4 -4
- package/dist/docs/templates/code-wiki.html +28 -0
- package/dist/docs/templates/code-wiki.md +91 -0
- package/dist/docs/templates/demo.html +5 -5
- package/dist/docs/templates/pr-autofixer.html +4 -4
- package/dist/docs/templates/security-help.html +4 -4
- package/dist/docs/templates/security-reviewer.html +5 -5
- package/dist/docs/templates/triage.html +4 -4
- package/dist/docs/troubleshooting.html +4 -4
- package/dist/files-backends/cursor-hosted.d.ts +26 -4
- package/dist/files-backends/cursor-hosted.d.ts.map +1 -1
- package/dist/files-backends/cursor-hosted.js +32 -4
- package/dist/internal/advertise-tools.d.ts +2 -0
- package/dist/internal/advertise-tools.d.ts.map +1 -1
- package/dist/internal/advertise-tools.js +15 -1
- package/dist/internal/bounded.d.ts +7 -0
- package/dist/internal/bounded.d.ts.map +1 -0
- package/dist/internal/bounded.js +32 -0
- package/dist/internal/cli-deploy.d.ts.map +1 -1
- package/dist/internal/cli-deploy.js +7 -1
- package/dist/internal/conversation-mirror.d.ts +11 -8
- package/dist/internal/conversation-mirror.d.ts.map +1 -1
- package/dist/internal/conversation-mirror.js +116 -55
- package/dist/internal/cursor/backend-client.d.ts.map +1 -1
- package/dist/internal/cursor/backend-client.js +22 -48
- package/dist/internal/cursor/session-token.d.ts +45 -0
- package/dist/internal/cursor/session-token.d.ts.map +1 -0
- package/dist/internal/cursor/session-token.js +99 -0
- package/dist/internal/cursor-agent-template.d.ts +1 -1
- package/dist/internal/cursor-agent-template.d.ts.map +1 -1
- package/dist/internal/cursor-agent-template.js +1 -0
- package/dist/internal/framework-file-storage.d.ts +61 -0
- package/dist/internal/framework-file-storage.d.ts.map +1 -0
- package/dist/internal/framework-file-storage.js +204 -0
- package/dist/internal/framework-storage-selection.d.ts +11 -5
- package/dist/internal/framework-storage-selection.d.ts.map +1 -1
- package/dist/internal/framework-storage-selection.js +38 -11
- package/dist/internal/hosted-delivery.d.ts +7 -0
- package/dist/internal/hosted-delivery.d.ts.map +1 -1
- package/dist/internal/hosted-delivery.js +4 -0
- package/dist/internal/init-project.d.ts.map +1 -1
- package/dist/internal/init-project.js +2 -0
- package/dist/internal/install-cursor-skills.d.ts.map +1 -1
- package/dist/internal/install-cursor-skills.js +1 -3
- package/dist/internal/managed-delivery.d.ts +80 -0
- package/dist/internal/managed-delivery.d.ts.map +1 -0
- package/dist/internal/managed-delivery.js +86 -0
- package/dist/internal/runtime-dispatch-runner.d.ts +5 -1
- package/dist/internal/runtime-dispatch-runner.d.ts.map +1 -1
- package/dist/internal/runtime-dispatch-runner.js +7 -0
- package/dist/internal/sdk-runner.d.ts +11 -0
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +39 -8
- package/dist/internal/server.js +1 -0
- package/dist/internal/session-engine.d.ts +13 -0
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +62 -3
- package/dist/internal/steering.d.ts +15 -0
- package/dist/internal/steering.d.ts.map +1 -0
- package/dist/internal/steering.js +18 -0
- package/dist/playground/assets/index-B1DDvBeC.css +1 -0
- package/dist/playground/assets/{index-CZA1uEWA.js → index-Cx9CclK_.js} +51 -51
- package/dist/playground/index.html +2 -2
- package/dist/storage-backends/cursor-hosted.d.ts +8 -5
- package/dist/storage-backends/cursor-hosted.d.ts.map +1 -1
- package/dist/storage-backends/cursor-hosted.js +4 -3
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/docs/README.md +3 -1
- package/docs/reference/cli.md +3 -2
- package/docs/templates/code-wiki.md +96 -0
- package/package.json +2 -2
- package/skills/ab/SKILL.md +13 -97
- package/skills/create-agent/SKILL.md +123 -223
- package/skills/debug/SKILL.md +34 -68
- package/skills/evals/SKILL.md +55 -180
- package/skills/framework-map/SKILL.md +83 -145
- package/skills/github/SKILL.md +53 -111
- package/skills/hillclimb/SKILL.md +40 -163
- package/skills/mcp-auth/SKILL.md +48 -107
- package/skills/otel/SKILL.md +22 -68
- package/skills/setup-slack/SKILL.md +77 -208
- package/src/channels/deployments/types.ts +1 -0
- package/src/channels/origin/api.ts +242 -30
- package/src/channels/origin/binding.ts +2 -2
- package/src/channels/origin/checks.ts +6 -6
- package/src/channels/origin/cursor-account.ts +5 -3
- package/src/channels/slack/api.ts +41 -5
- package/src/channels/slack/defaults.ts +15 -49
- package/src/channels/slack/dispatch.ts +56 -22
- package/src/channels/slack/inbound.ts +43 -0
- package/src/channels/slack/live-delivery.ts +235 -114
- package/src/channels/slack/manifest.ts +5 -1
- package/src/channels/slack/nudge-carrier.ts +48 -1
- package/src/channels/slack/slack-channel.ts +2 -0
- package/src/files-backends/cursor-hosted.ts +40 -7
- package/src/internal/advertise-tools.ts +18 -2
- package/src/internal/bounded.ts +28 -0
- package/src/internal/cli-deploy.ts +12 -0
- package/src/internal/conversation-mirror.ts +145 -69
- package/src/internal/cursor/backend-client.ts +34 -58
- package/src/internal/cursor/session-token.ts +115 -0
- package/src/internal/cursor-agent-template.ts +1 -0
- package/src/internal/framework-file-storage.ts +222 -0
- package/src/internal/framework-storage-selection.ts +51 -11
- package/src/internal/hosted-delivery.ts +10 -0
- package/src/internal/init-project.ts +2 -0
- package/src/internal/install-cursor-skills.ts +1 -4
- package/src/internal/managed-delivery.ts +125 -0
- package/src/internal/runtime-dispatch-runner.ts +10 -0
- package/src/internal/sdk-runner.ts +56 -8
- package/src/internal/server.ts +2 -0
- package/src/internal/session-engine.ts +64 -4
- package/src/internal/steering.ts +17 -0
- package/src/storage-backends/cursor-hosted.ts +9 -7
- package/src/types.ts +2 -1
- package/templates/code-wiki/README.md +34 -0
- package/templates/code-wiki/agent/agent.ts +8 -0
- package/templates/code-wiki/agent/channels/github.ts +144 -0
- package/templates/code-wiki/agent/instructions.md +39 -0
- package/templates/code-wiki/agent/lib/repos.ts +5 -0
- package/templates/code-wiki/agent/lib/wiki.ts +22 -0
- package/templates/code-wiki/agent/tools/apply_wiki.ts +219 -0
- package/templates/code-wiki/evals/evals.config.ts +5 -0
- package/templates/code-wiki/evals/wiki.eval.ts +132 -0
- package/templates/code-wiki/init.json +25 -0
- package/templates/code-wiki/package.json +18 -0
- package/templates/code-wiki/tsconfig.json +12 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.oqPawjiD.js +0 -1
- package/dist/docs/assets/index.md.BoHaMdeZ.js +0 -5
- package/dist/internal/deployment-scm-event-stream.d.ts +0 -116
- package/dist/internal/deployment-scm-event-stream.d.ts.map +0 -1
- package/dist/internal/deployment-scm-event-stream.js +0 -474
- package/dist/playground/assets/index-CF7hUDnQ.css +0 -1
- package/src/internal/deployment-scm-event-stream.ts +0 -593
- /package/dist/docs/assets/{reference_cli.md.BsMOxDvh.lean.js → reference_cli.md.CCnG-nJx.lean.js} +0 -0
|
@@ -24,13 +24,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
24
24
|
import { randomUUID } from "node:crypto";
|
|
25
25
|
import { z } from "zod";
|
|
26
26
|
import { boundedToolAnnotations } from "../mcp-host.js";
|
|
27
|
+
import { CURSOR_SESSION_EXCHANGE_PATH, CursorSessionExchangeError, exchangeCursorApiKeyForSession, SESSION_TOKEN_EXPIRY_LEEWAY_MS, } from "./session-token.js";
|
|
27
28
|
const CLIENT_VERSION = "agent-serve-0.1.0";
|
|
28
|
-
const EXCHANGE_PATH = "/auth/exchange_user_api_key";
|
|
29
29
|
const SERVICE_PREFIX = "/aiserver.v1.DashboardService";
|
|
30
|
-
/** Re-exchange when the cached token is within this window of expiry. */
|
|
31
|
-
const TOKEN_EXPIRY_LEEWAY_MS = 5 * 60 * 1000;
|
|
32
|
-
/** Fallback token lifetime when the JWT `exp` claim cannot be parsed. */
|
|
33
|
-
const FALLBACK_TOKEN_LIFETIME_MS = 30 * 60 * 1000;
|
|
34
30
|
const LIST_TIMEOUT_MS = 60000;
|
|
35
31
|
/** Backend-executed tools call out to third-party servers; be generous. */
|
|
36
32
|
const EXECUTE_TIMEOUT_MS = 120000;
|
|
@@ -374,7 +370,7 @@ export class CursorBackendClient {
|
|
|
374
370
|
this.tokenExchange = undefined;
|
|
375
371
|
}
|
|
376
372
|
if (this.token !== undefined &&
|
|
377
|
-
Date.now() < this.token.expiresAtMs -
|
|
373
|
+
Date.now() < this.token.expiresAtMs - SESSION_TOKEN_EXPIRY_LEEWAY_MS) {
|
|
378
374
|
return Promise.resolve(this.token.value);
|
|
379
375
|
}
|
|
380
376
|
// Single-flight: concurrent tool calls share one exchange.
|
|
@@ -388,38 +384,33 @@ export class CursorBackendClient {
|
|
|
388
384
|
exchangeApiKey() {
|
|
389
385
|
return __awaiter(this, void 0, void 0, function* () {
|
|
390
386
|
const apiKey = this.currentApiKey();
|
|
391
|
-
let
|
|
387
|
+
let session;
|
|
392
388
|
try {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
authorization: `Bearer ${apiKey}`,
|
|
398
|
-
},
|
|
399
|
-
body: "{}",
|
|
400
|
-
signal: AbortSignal.timeout(30000),
|
|
389
|
+
session = yield exchangeCursorApiKeyForSession({
|
|
390
|
+
exchangeUrl: `${this.backendUrl}${CURSOR_SESSION_EXCHANGE_PATH}`,
|
|
391
|
+
apiKey,
|
|
392
|
+
fetchImpl: this.fetchImpl,
|
|
401
393
|
});
|
|
402
394
|
}
|
|
403
395
|
catch (error) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
396
|
+
if (error instanceof CursorSessionExchangeError) {
|
|
397
|
+
if (error.status === undefined) {
|
|
398
|
+
throw new CursorBackendError(`Could not reach the Cursor backend at ${this.backendUrl}: ${error.message}`);
|
|
399
|
+
}
|
|
400
|
+
if (error.status >= 200 && error.status < 300) {
|
|
401
|
+
// 2xx without a token in the body.
|
|
402
|
+
throw new CursorBackendError("Cursor API key exchange returned no access token.");
|
|
403
|
+
}
|
|
404
|
+
throw new CursorBackendError(error.status === 401
|
|
405
|
+
? "The Cursor API key was rejected. Run `agent-serve login` again or update CURSOR_API_KEY."
|
|
406
|
+
: `Cursor API key exchange failed (${error.status}).`, error.status);
|
|
407
|
+
}
|
|
408
|
+
throw error;
|
|
411
409
|
}
|
|
412
|
-
|
|
413
|
-
if (!body.success || body.data.accessToken === "") {
|
|
414
|
-
throw new CursorBackendError("Cursor API key exchange returned no access token.");
|
|
415
|
-
}
|
|
416
|
-
this.token = {
|
|
417
|
-
value: body.data.accessToken,
|
|
418
|
-
expiresAtMs: jwtExpiryMs(body.data.accessToken),
|
|
419
|
-
};
|
|
410
|
+
this.token = { value: session.token, expiresAtMs: session.expiresAtMs };
|
|
420
411
|
this.lastExchangedApiKey = apiKey;
|
|
421
412
|
this.logger("[agent-sdk] cursor account: minted a fresh access token");
|
|
422
|
-
return
|
|
413
|
+
return session.token;
|
|
423
414
|
});
|
|
424
415
|
}
|
|
425
416
|
}
|
|
@@ -502,7 +493,6 @@ export function revokeMintedUserApiKey(args) {
|
|
|
502
493
|
// ============================================================================
|
|
503
494
|
// Helpers
|
|
504
495
|
// ============================================================================
|
|
505
|
-
const accessTokenResponseSchema = z.object({ accessToken: z.string() });
|
|
506
496
|
function safeJsonParse(text) {
|
|
507
497
|
try {
|
|
508
498
|
return JSON.parse(text);
|
|
@@ -648,22 +638,6 @@ function retryAfterMsFromResponse(response) {
|
|
|
648
638
|
}
|
|
649
639
|
return Math.min(retryAfter * 1000, MAX_GITHUB_TOKEN_RETRY_AFTER_MS);
|
|
650
640
|
}
|
|
651
|
-
function jwtExpiryMs(token) {
|
|
652
|
-
try {
|
|
653
|
-
const payload = token.split(".")[1];
|
|
654
|
-
if (payload === undefined) {
|
|
655
|
-
throw new Error("not a JWT");
|
|
656
|
-
}
|
|
657
|
-
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
658
|
-
if (typeof claims.exp === "number") {
|
|
659
|
-
return claims.exp * 1000;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
catch (_a) {
|
|
663
|
-
// Opaque token — assume a conservative lifetime.
|
|
664
|
-
}
|
|
665
|
-
return Date.now() + FALLBACK_TOKEN_LIFETIME_MS;
|
|
666
|
-
}
|
|
667
641
|
function describeError(error) {
|
|
668
642
|
return error instanceof Error ? error.message : String(error);
|
|
669
643
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared `CURSOR_API_KEY` → Cursor session-token exchange primitive
|
|
3
|
+
* (`POST /auth/exchange_user_api_key`, ~1h session).
|
|
4
|
+
*
|
|
5
|
+
* Both `CursorBackendClient` (dashboard RPCs) and the Origin channel's
|
|
6
|
+
* session provider (`cursorSessionTokenProvider` in
|
|
7
|
+
* `../../channels/origin/api.ts`) mint through this module, so the URL,
|
|
8
|
+
* request shape, response parsing, JWT-expiry handling, and renewal
|
|
9
|
+
* constants cannot drift between the two. Callers own their caching and
|
|
10
|
+
* retry policies; this module owns exactly one exchange round trip.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CURSOR_SESSION_EXCHANGE_PATH = "/auth/exchange_user_api_key";
|
|
13
|
+
/** Re-exchange when the cached session is within this window of expiry. */
|
|
14
|
+
export declare const SESSION_TOKEN_EXPIRY_LEEWAY_MS: number;
|
|
15
|
+
/** Fallback session lifetime when the JWT `exp` claim cannot be parsed. */
|
|
16
|
+
export declare const SESSION_TOKEN_FALLBACK_LIFETIME_MS: number;
|
|
17
|
+
/**
|
|
18
|
+
* Exchange failure. `status` is the HTTP status when the backend answered,
|
|
19
|
+
* and undefined for network/transport errors. `detail` carries the server's
|
|
20
|
+
* `error` field when present so callers can surface the reason verbatim.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CursorSessionExchangeError extends Error {
|
|
23
|
+
readonly status?: number | undefined;
|
|
24
|
+
readonly detail?: string | undefined;
|
|
25
|
+
constructor(message: string, status?: number | undefined, detail?: string | undefined);
|
|
26
|
+
}
|
|
27
|
+
/** Epoch-ms expiry from a JWT `exp` claim, or undefined when unparsable. */
|
|
28
|
+
export declare function jwtExpiryMs(token: string): number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* One exchange round trip. Throws {@link CursorSessionExchangeError} on
|
|
31
|
+
* transport failure, a non-2xx response, or a token-free body. `expiresAtMs`
|
|
32
|
+
* comes from the session JWT's `exp` claim, falling back to
|
|
33
|
+
* {@link SESSION_TOKEN_FALLBACK_LIFETIME_MS} for opaque tokens.
|
|
34
|
+
*/
|
|
35
|
+
export declare function exchangeCursorApiKeyForSession(args: {
|
|
36
|
+
/** Full exchange URL (base + {@link CURSOR_SESSION_EXCHANGE_PATH}). */
|
|
37
|
+
exchangeUrl: string;
|
|
38
|
+
apiKey: string;
|
|
39
|
+
fetchImpl?: typeof fetch;
|
|
40
|
+
nowMs?: number;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
token: string;
|
|
43
|
+
expiresAtMs: number;
|
|
44
|
+
}>;
|
|
45
|
+
//# sourceMappingURL=session-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-token.d.ts","sourceRoot":"","sources":["../../../src/internal/cursor/session-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,4BAA4B,gCAAgC,CAAC;AAC1E,2EAA2E;AAC3E,eAAO,MAAM,8BAA8B,EAAE,MAAsB,CAAC;AACpE,2EAA2E;AAC3E,eAAO,MAAM,kCAAkC,EAAE,MAAuB,CAAC;AAGzE;;;;GAIG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IAGjD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAH1B,YACE,OAAO,EAAE,MAAM,EACN,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,MAAM,CAAC,EAAE,MAAM,YAAA,EAIzB;CACF;AAED,4EAA4E;AAC5E,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAa7D;AAED;;;;;GAKG;AACH,wBAAsB,8BAA8B,CAAC,IAAI,EAAE;IACzD,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAmDlD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared `CURSOR_API_KEY` → Cursor session-token exchange primitive
|
|
3
|
+
* (`POST /auth/exchange_user_api_key`, ~1h session).
|
|
4
|
+
*
|
|
5
|
+
* Both `CursorBackendClient` (dashboard RPCs) and the Origin channel's
|
|
6
|
+
* session provider (`cursorSessionTokenProvider` in
|
|
7
|
+
* `../../channels/origin/api.ts`) mint through this module, so the URL,
|
|
8
|
+
* request shape, response parsing, JWT-expiry handling, and renewal
|
|
9
|
+
* constants cannot drift between the two. Callers own their caching and
|
|
10
|
+
* retry policies; this module owns exactly one exchange round trip.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const CURSOR_SESSION_EXCHANGE_PATH = "/auth/exchange_user_api_key";
|
|
22
|
+
/** Re-exchange when the cached session is within this window of expiry. */
|
|
23
|
+
export const SESSION_TOKEN_EXPIRY_LEEWAY_MS = 5 * 60 * 1000;
|
|
24
|
+
/** Fallback session lifetime when the JWT `exp` claim cannot be parsed. */
|
|
25
|
+
export const SESSION_TOKEN_FALLBACK_LIFETIME_MS = 30 * 60 * 1000;
|
|
26
|
+
const EXCHANGE_TIMEOUT_MS = 30000;
|
|
27
|
+
/**
|
|
28
|
+
* Exchange failure. `status` is the HTTP status when the backend answered,
|
|
29
|
+
* and undefined for network/transport errors. `detail` carries the server's
|
|
30
|
+
* `error` field when present so callers can surface the reason verbatim.
|
|
31
|
+
*/
|
|
32
|
+
export class CursorSessionExchangeError extends Error {
|
|
33
|
+
constructor(message, status, detail) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.status = status;
|
|
36
|
+
this.detail = detail;
|
|
37
|
+
this.name = "CursorSessionExchangeError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Epoch-ms expiry from a JWT `exp` claim, or undefined when unparsable. */
|
|
41
|
+
export function jwtExpiryMs(token) {
|
|
42
|
+
try {
|
|
43
|
+
const payload = token.split(".")[1];
|
|
44
|
+
if (payload === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
48
|
+
return typeof claims.exp === "number" ? claims.exp * 1000 : undefined;
|
|
49
|
+
}
|
|
50
|
+
catch (_a) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One exchange round trip. Throws {@link CursorSessionExchangeError} on
|
|
56
|
+
* transport failure, a non-2xx response, or a token-free body. `expiresAtMs`
|
|
57
|
+
* comes from the session JWT's `exp` claim, falling back to
|
|
58
|
+
* {@link SESSION_TOKEN_FALLBACK_LIFETIME_MS} for opaque tokens.
|
|
59
|
+
*/
|
|
60
|
+
export function exchangeCursorApiKeyForSession(args) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
const fetchImpl = (_a = args.fetchImpl) !== null && _a !== void 0 ? _a : fetch;
|
|
64
|
+
let response;
|
|
65
|
+
try {
|
|
66
|
+
response = yield fetchImpl(args.exchangeUrl, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: {
|
|
69
|
+
"content-type": "application/json",
|
|
70
|
+
authorization: `Bearer ${args.apiKey}`,
|
|
71
|
+
},
|
|
72
|
+
body: "{}",
|
|
73
|
+
signal: AbortSignal.timeout(EXCHANGE_TIMEOUT_MS),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw new CursorSessionExchangeError(`Could not reach the Cursor session exchange at ${args.exchangeUrl}: ${error instanceof Error ? error.message : String(error)}`);
|
|
78
|
+
}
|
|
79
|
+
const body = yield response.json().catch(() => undefined);
|
|
80
|
+
const record = typeof body === "object" && body !== null && !Array.isArray(body)
|
|
81
|
+
? body
|
|
82
|
+
: {};
|
|
83
|
+
const detail = typeof record.error === "string" && record.error !== ""
|
|
84
|
+
? record.error
|
|
85
|
+
: undefined;
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
throw new CursorSessionExchangeError(`Cursor session exchange failed with HTTP ${response.status}${detail === undefined ? "" : ` (${detail})`}.`, response.status, detail);
|
|
88
|
+
}
|
|
89
|
+
const token = record.accessToken;
|
|
90
|
+
if (typeof token !== "string" || token === "") {
|
|
91
|
+
throw new CursorSessionExchangeError("Cursor session exchange returned no access token.", response.status);
|
|
92
|
+
}
|
|
93
|
+
const nowMs = (_b = args.nowMs) !== null && _b !== void 0 ? _b : Date.now();
|
|
94
|
+
return {
|
|
95
|
+
token,
|
|
96
|
+
expiresAtMs: (_c = jwtExpiryMs(token)) !== null && _c !== void 0 ? _c : nowMs + SESSION_TOKEN_FALLBACK_LIFETIME_MS,
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const TEMPLATE_NAMES: readonly ["agentic-owners", "demo", "pr-autofixer", "security-help", "security-reviewer", "triage-linear", "triage-jira"];
|
|
1
|
+
declare const TEMPLATE_NAMES: readonly ["agentic-owners", "code-wiki", "demo", "pr-autofixer", "security-help", "security-reviewer", "triage-linear", "triage-jira"];
|
|
2
2
|
export type TemplateName = (typeof TEMPLATE_NAMES)[number];
|
|
3
3
|
export declare function canonicalTemplateName(name: string): string;
|
|
4
4
|
export declare function isTemplateName(name: string): name is TemplateName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursor-agent-template.d.ts","sourceRoot":"","sources":["../../src/internal/cursor-agent-template.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,cAAc,YAClB,gBAAgB,EAChB,MAAM,EACN,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,aAAa,CACL,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAG3D,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,YAAY,CAEjE;AAED,yEAAyE;AACzE,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAY3E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOtE"}
|
|
1
|
+
{"version":3,"file":"cursor-agent-template.d.ts","sourceRoot":"","sources":["../../src/internal/cursor-agent-template.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,cAAc,YAClB,gBAAgB,EAChB,WAAW,EACX,MAAM,EACN,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,aAAa,CACL,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAG3D,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,YAAY,CAEjE;AAED,yEAAyE;AACzE,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAY3E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOtE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-level file storage for v2 hosted engines.
|
|
3
|
+
*
|
|
4
|
+
* Hosted deployments carry two file stores with different audiences:
|
|
5
|
+
*
|
|
6
|
+
* - the **user-level** store (`AGENT_SERVE_STORE_SOURCE_ID`) holds
|
|
7
|
+
* author-facing bytes — `ctx.host.files`, skills, memory, artifacts — and
|
|
8
|
+
* is browsable from the dashboard and mountable on cloud-runtime VMs;
|
|
9
|
+
* - the **framework-level** store (`AGENT_SERVE_FRAMEWORK_STORE_SOURCE_ID`)
|
|
10
|
+
* holds engine-owned session state — session records, event transcripts,
|
|
11
|
+
* the continuation index, and the SDK conversation mirror — and is never
|
|
12
|
+
* exposed to authors or models.
|
|
13
|
+
*
|
|
14
|
+
* This module puts framework session state on the framework store. The
|
|
15
|
+
* {@link storageKeys} scheme was designed for exactly this: keys are a
|
|
16
|
+
* stable versioned contract that sinks may route on, so
|
|
17
|
+
* {@link composeFrameworkStorage} splits one {@link StorageConfig} by key
|
|
18
|
+
* kind — `session` / `session-events` / `continuation` go to the framework
|
|
19
|
+
* file store (file-shaped; the store accepts values up to 64 MiB per
|
|
20
|
+
* object without chunking, versus the KV proxy's 1 MiB row cap), while
|
|
21
|
+
* author `kv`, eval runs, A/B samples, and conditional writes stay on the
|
|
22
|
+
* control-plane KV proxy (the dashboard reads them there, and CAS needs a
|
|
23
|
+
* database).
|
|
24
|
+
*
|
|
25
|
+
* v2 only, by construction: the composite is selected in
|
|
26
|
+
* framework-storage-selection.ts, which v1 never reaches with a
|
|
27
|
+
* platform-selected definition.
|
|
28
|
+
*/
|
|
29
|
+
import type { FileSink } from "../files.js";
|
|
30
|
+
import type { StorageConfig } from "../storage.js";
|
|
31
|
+
/**
|
|
32
|
+
* Whether a framework-minted key (or list prefix) belongs on the framework
|
|
33
|
+
* file store. Prefixes used by the coordinator are always at least
|
|
34
|
+
* kind-scoped (`…/{agent}/session/`), so a prefix routes wholly to one side.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isFrameworkFileKey(key: string): boolean;
|
|
37
|
+
/** The KV core over a {@link FileSink}: one JSON document per key. */
|
|
38
|
+
export type FileSinkStorageCore = Required<Pick<StorageConfig, "put" | "get" | "delete" | "list">>;
|
|
39
|
+
export declare function fileSinkStorageCore(sink: FileSink): FileSinkStorageCore;
|
|
40
|
+
/**
|
|
41
|
+
* Split one storage core by key kind: framework session state to `files`,
|
|
42
|
+
* everything else to `kv`. Spread over the KV backend when building the
|
|
43
|
+
* full definition so its `evals` / `abs` groups (and the cursor-hosted
|
|
44
|
+
* marker) ride along untouched; wrap the KV `cas` group with
|
|
45
|
+
* {@link frameworkGuardedCas} rather than spreading it as-is.
|
|
46
|
+
*/
|
|
47
|
+
export declare function composeFrameworkStorage(input: {
|
|
48
|
+
kv: FileSinkStorageCore;
|
|
49
|
+
files: FileSinkStorageCore;
|
|
50
|
+
}): FileSinkStorageCore;
|
|
51
|
+
/**
|
|
52
|
+
* The KV backend's conditional writes, refusing framework-file keys.
|
|
53
|
+
*
|
|
54
|
+
* CAS runs on the KV proxy (a database row version); the plain core routes
|
|
55
|
+
* framework session state to the file store. A future coordination path
|
|
56
|
+
* that CASes a `session/` or `continuation/` key would otherwise read and
|
|
57
|
+
* write a different store than the plain path — silent split-brain. Fail
|
|
58
|
+
* loudly instead; nothing in the package CASes those kinds today.
|
|
59
|
+
*/
|
|
60
|
+
export declare function frameworkGuardedCas(cas: NonNullable<StorageConfig["cas"]>): NonNullable<StorageConfig["cas"]>;
|
|
61
|
+
//# sourceMappingURL=framework-file-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-file-storage.d.ts","sourceRoot":"","sources":["../../src/internal/framework-file-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,eAAe,CAAC;AAejE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAavD;AAED,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CACxC,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC,CACvD,CAAC;AA0BF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,GAAG,mBAAmB,CAuDvE;AAcD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,EAAE,EAAE,mBAAmB,CAAC;IACxB,KAAK,EAAE,mBAAmB,CAAC;CAC5B,GAAG,mBAAmB,CAStB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,GACrC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CA0BnC"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-level file storage for v2 hosted engines.
|
|
3
|
+
*
|
|
4
|
+
* Hosted deployments carry two file stores with different audiences:
|
|
5
|
+
*
|
|
6
|
+
* - the **user-level** store (`AGENT_SERVE_STORE_SOURCE_ID`) holds
|
|
7
|
+
* author-facing bytes — `ctx.host.files`, skills, memory, artifacts — and
|
|
8
|
+
* is browsable from the dashboard and mountable on cloud-runtime VMs;
|
|
9
|
+
* - the **framework-level** store (`AGENT_SERVE_FRAMEWORK_STORE_SOURCE_ID`)
|
|
10
|
+
* holds engine-owned session state — session records, event transcripts,
|
|
11
|
+
* the continuation index, and the SDK conversation mirror — and is never
|
|
12
|
+
* exposed to authors or models.
|
|
13
|
+
*
|
|
14
|
+
* This module puts framework session state on the framework store. The
|
|
15
|
+
* {@link storageKeys} scheme was designed for exactly this: keys are a
|
|
16
|
+
* stable versioned contract that sinks may route on, so
|
|
17
|
+
* {@link composeFrameworkStorage} splits one {@link StorageConfig} by key
|
|
18
|
+
* kind — `session` / `session-events` / `continuation` go to the framework
|
|
19
|
+
* file store (file-shaped; the store accepts values up to 64 MiB per
|
|
20
|
+
* object without chunking, versus the KV proxy's 1 MiB row cap), while
|
|
21
|
+
* author `kv`, eval runs, A/B samples, and conditional writes stay on the
|
|
22
|
+
* control-plane KV proxy (the dashboard reads them there, and CAS needs a
|
|
23
|
+
* database).
|
|
24
|
+
*
|
|
25
|
+
* v2 only, by construction: the composite is selected in
|
|
26
|
+
* framework-storage-selection.ts, which v1 never reaches with a
|
|
27
|
+
* platform-selected definition.
|
|
28
|
+
*/
|
|
29
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
import { STORAGE_KEY_ROOT } from "../storage-protocol.js";
|
|
39
|
+
import { mapBounded } from "./bounded.js";
|
|
40
|
+
/**
|
|
41
|
+
* Key kinds (`agentkit/v1/{agent}/{kind}/…`) that live on the framework
|
|
42
|
+
* file store. Everything else stays on the KV sink.
|
|
43
|
+
*/
|
|
44
|
+
const FRAMEWORK_FILE_KINDS = new Set([
|
|
45
|
+
"session",
|
|
46
|
+
"session-events",
|
|
47
|
+
"continuation",
|
|
48
|
+
]);
|
|
49
|
+
/**
|
|
50
|
+
* Whether a framework-minted key (or list prefix) belongs on the framework
|
|
51
|
+
* file store. Prefixes used by the coordinator are always at least
|
|
52
|
+
* kind-scoped (`…/{agent}/session/`), so a prefix routes wholly to one side.
|
|
53
|
+
*/
|
|
54
|
+
export function isFrameworkFileKey(key) {
|
|
55
|
+
if (!key.startsWith(`${STORAGE_KEY_ROOT}/`)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const rest = key.slice(STORAGE_KEY_ROOT.length + 1);
|
|
59
|
+
const agentEnd = rest.indexOf("/");
|
|
60
|
+
if (agentEnd === -1) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const afterAgent = rest.slice(agentEnd + 1);
|
|
64
|
+
const kindEnd = afterAgent.indexOf("/");
|
|
65
|
+
const kind = kindEnd === -1 ? afterAgent : afterAgent.slice(0, kindEnd);
|
|
66
|
+
return FRAMEWORK_FILE_KINDS.has(kind);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Adapt a {@link FileSink} to the `defineStorage` KV core. Storage keys are
|
|
70
|
+
* framework-minted (URI-encoded, length-bounded segments — see
|
|
71
|
+
* {@link storageKeys}), so they are used as file keys verbatim; values are
|
|
72
|
+
* stored as JSON bytes. Parse failures throw: on the lazy-restore path a
|
|
73
|
+
* corrupt document must fail the follow-up rather than read as a miss, and
|
|
74
|
+
* the startup bulk restore already logs-and-skips a throwing `list`.
|
|
75
|
+
*/
|
|
76
|
+
/** Parallel per-key reads backing `list` (each is presign + object GET). */
|
|
77
|
+
const LIST_READ_CONCURRENCY = 8;
|
|
78
|
+
/**
|
|
79
|
+
* A storage key whose path the file store cannot represent (an empty, `.`,
|
|
80
|
+
* or `..` segment — possible only through caller-controlled segments such
|
|
81
|
+
* as continuation tokens or a caller-supplied session id). Such an object
|
|
82
|
+
* can never exist in the store, so reads are a definitive miss rather than
|
|
83
|
+
* a per-request 400 that the lazy-restore path would propagate forever.
|
|
84
|
+
*/
|
|
85
|
+
function isUnrepresentableFileKey(key) {
|
|
86
|
+
return key
|
|
87
|
+
.split("/")
|
|
88
|
+
.some((segment) => segment === "" || segment === "." || segment === "..");
|
|
89
|
+
}
|
|
90
|
+
export function fileSinkStorageCore(sink) {
|
|
91
|
+
return {
|
|
92
|
+
put(key, value) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
if (isUnrepresentableFileKey(key)) {
|
|
95
|
+
// Loud rather than silent: the coordinator logs and drops failed
|
|
96
|
+
// mirror writes (at-most-once), and awaited callers must not
|
|
97
|
+
// believe an impossible write landed.
|
|
98
|
+
throw new Error(`framework file storage: key "${key}" has a path segment the store cannot represent`);
|
|
99
|
+
}
|
|
100
|
+
yield sink.put(key, new TextEncoder().encode(JSON.stringify(value)));
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
get(key) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
if (isUnrepresentableFileKey(key)) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const body = yield sink.get(key);
|
|
109
|
+
if (body === undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
return decodeDocument(key, body instanceof Uint8Array ? body : body.body);
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
delete(key) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
if (isUnrepresentableFileKey(key)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
yield sink.delete(key);
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
list(prefix) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const entries = yield sink.list(prefix);
|
|
126
|
+
// FileSink.list returns metadata only, so each value is its own
|
|
127
|
+
// read; bound the fan-out — a bulk read here sits on restore paths.
|
|
128
|
+
const bodies = yield mapBounded(entries, LIST_READ_CONCURRENCY, (entry) => sink.get(entry.key));
|
|
129
|
+
const out = [];
|
|
130
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
131
|
+
const entry = entries[index];
|
|
132
|
+
const body = bodies[index];
|
|
133
|
+
if (entry === undefined || body === undefined) {
|
|
134
|
+
// Deleted between list and read; a miss is not corruption.
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
out.push({
|
|
138
|
+
key: entry.key,
|
|
139
|
+
value: decodeDocument(entry.key, body instanceof Uint8Array ? body : body.body),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function decodeDocument(key, bytes) {
|
|
148
|
+
try {
|
|
149
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
throw new Error(`framework file storage: stored document at "${key}" is not JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Split one storage core by key kind: framework session state to `files`,
|
|
157
|
+
* everything else to `kv`. Spread over the KV backend when building the
|
|
158
|
+
* full definition so its `evals` / `abs` groups (and the cursor-hosted
|
|
159
|
+
* marker) ride along untouched; wrap the KV `cas` group with
|
|
160
|
+
* {@link frameworkGuardedCas} rather than spreading it as-is.
|
|
161
|
+
*/
|
|
162
|
+
export function composeFrameworkStorage(input) {
|
|
163
|
+
const route = (key) => isFrameworkFileKey(key) ? input.files : input.kv;
|
|
164
|
+
return {
|
|
165
|
+
put: (key, value, ctx) => route(key).put(key, value, ctx),
|
|
166
|
+
get: (key, ctx) => route(key).get(key, ctx),
|
|
167
|
+
delete: (key, ctx) => route(key).delete(key, ctx),
|
|
168
|
+
list: (prefix, ctx) => route(prefix).list(prefix, ctx),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The KV backend's conditional writes, refusing framework-file keys.
|
|
173
|
+
*
|
|
174
|
+
* CAS runs on the KV proxy (a database row version); the plain core routes
|
|
175
|
+
* framework session state to the file store. A future coordination path
|
|
176
|
+
* that CASes a `session/` or `continuation/` key would otherwise read and
|
|
177
|
+
* write a different store than the plain path — silent split-brain. Fail
|
|
178
|
+
* loudly instead; nothing in the package CASes those kinds today.
|
|
179
|
+
*/
|
|
180
|
+
export function frameworkGuardedCas(cas) {
|
|
181
|
+
const refuse = (key) => {
|
|
182
|
+
if (isFrameworkFileKey(key)) {
|
|
183
|
+
throw new Error(`framework file storage: conditional writes are KV-only, but "${key}" routes to the framework file store`);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
getWithVersion: (key, ctx) => {
|
|
188
|
+
refuse(key);
|
|
189
|
+
return cas.getWithVersion(key, ctx);
|
|
190
|
+
},
|
|
191
|
+
putIfAbsent: (key, value, ctx) => {
|
|
192
|
+
refuse(key);
|
|
193
|
+
return cas.putIfAbsent(key, value, ctx);
|
|
194
|
+
},
|
|
195
|
+
putIfVersion: (key, value, expectedVersion, ctx) => {
|
|
196
|
+
refuse(key);
|
|
197
|
+
return cas.putIfVersion(key, value, expectedVersion, ctx);
|
|
198
|
+
},
|
|
199
|
+
listKeys: (prefix, ctx) => {
|
|
200
|
+
refuse(prefix);
|
|
201
|
+
return cas.listKeys(prefix, ctx);
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
@@ -17,11 +17,17 @@
|
|
|
17
17
|
*
|
|
18
18
|
* - **Cursor-managed hosting** (the deployment-generation environment
|
|
19
19
|
* variable is set, same signal that registers `GET /v1/manifest`):
|
|
20
|
-
* the Cursor-hosted backend
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
20
|
+
* the Cursor-hosted backend. When the deployment carries a
|
|
21
|
+
* **framework-level file store**
|
|
22
|
+
* (`AGENT_SERVE_FRAMEWORK_STORE_SOURCE_ID`), session records, event
|
|
23
|
+
* transcripts, and the continuation index live there — file-shaped state
|
|
24
|
+
* on file storage, apart from the author-facing user store — while
|
|
25
|
+
* `host.kv`, eval runs, A/B samples, and conditional writes stay on the
|
|
26
|
+
* control-plane KV proxy (see framework-file-storage.ts). Without one
|
|
27
|
+
* (a deploy predating framework-store provisioning), everything goes to
|
|
28
|
+
* the KV proxy as before. The API key resolves through the full
|
|
29
|
+
* credential chain on every call because hosted freeze snapshots listen
|
|
30
|
+
* unsigned and the binder drops the key file after restore.
|
|
25
31
|
* - **Self-hosted**: no mirror. `--state-root` is the durable copy, which
|
|
26
32
|
* is correct when the operator owns the disk.
|
|
27
33
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-storage-selection.d.ts","sourceRoot":"","sources":["../../src/internal/framework-storage-selection.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"framework-storage-selection.d.ts","sourceRoot":"","sources":["../../src/internal/framework-storage-selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAMH,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AASrD,MAAM,WAAW,8BAA8B;IAC7C,2FAA2F;IAC3F,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACjD,0DAA0D;IAC1D,QAAQ,CAAC,YAAY,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACtD,iEAAiE;IACjE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACnD;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,8BAA8B,GACpC,iBAAiB,GAAG,SAAS,CAoD/B"}
|