mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-05 12:13:05 +08:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe17e15e75 | ||
|
|
24177fcb6e | ||
|
|
7fa4953883 | ||
|
|
4bb4ca5c8d | ||
|
|
4ddd3adb3f | ||
|
|
1a0cf89fe1 |
+1
-1
@@ -3,7 +3,7 @@ claude-server.tar
|
||||
dist
|
||||
.task
|
||||
/local-docs/
|
||||
bin
|
||||
/bin/
|
||||
logs/
|
||||
cursor-server.db
|
||||
cursor-server.db-shm
|
||||
|
||||
Generated
+1
-1
@@ -1128,7 +1128,7 @@ checksum = "52560adf09603e58c9a7ee1fe1dcb95a16927b17c127f0ac02d6e768a0e25bc1"
|
||||
|
||||
[[package]]
|
||||
name = "cursor-byok-desktop"
|
||||
version = "0.1.0-beta.4"
|
||||
version = "0.1.0-beta.6"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"cursor-server",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
LOCAL_TAURI_SIGNING_KEY := $(CURDIR)/.tauri/cursor-byok.local.key
|
||||
|
||||
.PHONY: check dev-web dev-server dev-desktop build-web build-server build-desktop build-docker
|
||||
|
||||
check:
|
||||
@@ -21,8 +23,13 @@ build-web:
|
||||
build-server:
|
||||
cargo build --release --package cursor-server --bin cursor-server
|
||||
|
||||
build-desktop:
|
||||
npm --prefix apps/desktop run tauri:build
|
||||
$(LOCAL_TAURI_SIGNING_KEY):
|
||||
@install -d -m 700 "$(dir $@)"
|
||||
@apps/desktop/node_modules/.bin/tauri signer generate --ci --write-keys "$@" >/dev/null
|
||||
@chmod 600 "$@" "$@.pub"
|
||||
|
||||
build-desktop: $(LOCAL_TAURI_SIGNING_KEY)
|
||||
TAURI_SIGNING_PRIVATE_KEY="$(LOCAL_TAURI_SIGNING_KEY)" TAURI_SIGNING_PRIVATE_KEY_PASSWORD="" npm --prefix apps/desktop run tauri:build
|
||||
|
||||
build-docker:
|
||||
docker build --tag cursor-byok:local .
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cursor-byok-desktop",
|
||||
"version": "0.1.0-beta.4",
|
||||
"version": "0.1.0-beta.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cursor-byok-desktop",
|
||||
"version": "0.1.0-beta.4",
|
||||
"version": "0.1.0-beta.6",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@floating-ui/dom": "^1.8.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cursor-byok-desktop",
|
||||
"version": "0.1.0-beta.4",
|
||||
"version": "0.1.0-beta.6",
|
||||
"description": "Cursor BYOK desktop management application",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cursor-byok-desktop"
|
||||
version = "0.1.0-beta.4"
|
||||
version = "0.1.0-beta.6"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Cursor BYOK",
|
||||
"version": "0.1.0-beta.4",
|
||||
"version": "0.1.0-beta.6",
|
||||
"identifier": "dev.cursorbyok.desktop",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev",
|
||||
|
||||
@@ -174,6 +174,7 @@ export function VirtualList<TItem>(props: VirtualListProps<TItem>) {
|
||||
const shouldResetScrollRef = useRef(false)
|
||||
const scrollApiRef = useRef<ScrollAreaApi | null>(null)
|
||||
const scrollStateRef = useRef<ScrollAreaState | null>(null)
|
||||
const contentElementRef = useRef<HTMLDivElement | null>(null)
|
||||
const spacerRef = useRef<HTMLDivElement | null>(null)
|
||||
const [contentInsets, setContentInsets] = useState<ContentInsets>({
|
||||
top: 0,
|
||||
@@ -192,7 +193,8 @@ export function VirtualList<TItem>(props: VirtualListProps<TItem>) {
|
||||
})
|
||||
const [, forceUpdate] = useState(0)
|
||||
|
||||
const setContentRef = useCallback((node: HTMLDivElement | null) => {
|
||||
const readContentInsets = useCallback(() => {
|
||||
const node = contentElementRef.current
|
||||
const styles = node ? getComputedStyle(node) : null
|
||||
const nextInsets = {
|
||||
top: styles ? Number.parseFloat(styles.paddingTop) || 0 : 0,
|
||||
@@ -205,6 +207,26 @@ export function VirtualList<TItem>(props: VirtualListProps<TItem>) {
|
||||
)
|
||||
}, [])
|
||||
|
||||
const setContentRef = useCallback((node: HTMLDivElement | null) => {
|
||||
contentElementRef.current = node
|
||||
readContentInsets()
|
||||
}, [readContentInsets])
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const node = contentElementRef.current
|
||||
if (!node) return
|
||||
|
||||
readContentInsets()
|
||||
const resizeObserver = new ResizeObserver(readContentInsets)
|
||||
resizeObserver.observe(node)
|
||||
const frame = requestAnimationFrame(readContentInsets)
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(frame)
|
||||
resizeObserver.disconnect()
|
||||
}
|
||||
}, [readContentInsets])
|
||||
|
||||
const contentInsetTop = contentInsets.top
|
||||
|
||||
if (!scrollStateRef.current) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,929 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package git_forge.v1;
|
||||
|
||||
option go_package = "github.com/leookun/cursor-byok/cursor-proto/gen/git_forge/v1;git_forgev1";
|
||||
|
||||
// Copied from: local:git_forge.v1.BatchGetBlobOidsRequest (var: Gn)
|
||||
message BatchGetBlobOidsRequest {
|
||||
string repo_uuid = 1;
|
||||
string revision = 2;
|
||||
repeated string paths = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BatchGetBlobOidsResponse (var: Vn)
|
||||
message BatchGetBlobOidsResponse {
|
||||
repeated BlobOidResult results = 1;
|
||||
string resolved_commit_sha = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BatchGetCommitMetadataRequest (var: Ut)
|
||||
message BatchGetCommitMetadataRequest {
|
||||
string repo_uuid = 1;
|
||||
repeated string revisions = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BatchGetCommitMetadataResponse (var: Gt)
|
||||
message BatchGetCommitMetadataResponse {
|
||||
repeated BatchGetCommitMetadataResult results = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BatchGetCommitMetadataResult (var: Qt)
|
||||
message BatchGetCommitMetadataResult {
|
||||
string revision = 1;
|
||||
CommitMetadata metadata = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BatchGetRepoContentRequest (var: Un)
|
||||
message BatchGetRepoContentRequest {
|
||||
string repo_uuid = 1;
|
||||
string revision = 2;
|
||||
repeated string paths = 3;
|
||||
optional uint64 max_file_size = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BatchGetRepoContentResponse (var: Qn)
|
||||
message BatchGetRepoContentResponse {
|
||||
repeated BatchRepoContentResult results = 1;
|
||||
string resolved_commit_sha = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BatchRepoContentResult (var: xn)
|
||||
message BatchRepoContentResult {
|
||||
string path = 1;
|
||||
bool found = 2;
|
||||
oneof content {
|
||||
FileContent file_content = 3;
|
||||
DirectoryContent directory_content = 4;
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BlameChunk (var: GSv)
|
||||
message BlameChunk {
|
||||
repeated ShortCommit commits = 1;
|
||||
repeated BlameLineRange line_ranges = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BlameLineRange (var: VSv)
|
||||
message BlameLineRange {
|
||||
bytes commit_sha = 1;
|
||||
uint32 start_in_blamed_file = 2;
|
||||
uint32 len = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BlobOidResult (var: Hn)
|
||||
message BlobOidResult {
|
||||
string path = 1;
|
||||
bool found = 2;
|
||||
string blob_oid = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.BranchDeletion (var: Or)
|
||||
message BranchDeletion {
|
||||
string target_ref = 1;
|
||||
string expected_head_sha = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CanMergeRequest (var: on)
|
||||
message CanMergeRequest {
|
||||
string repo_uuid = 1;
|
||||
string ours = 2;
|
||||
string theirs = 3;
|
||||
uint64 change_number = 4;
|
||||
MergeMode mode = 7;
|
||||
bool use_git_conflict_semantics = 8;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CanMergeResponse (var: LSv)
|
||||
message CanMergeResponse {
|
||||
bool can_merge_without_conflicts = 1;
|
||||
optional bytes merged_tree_sha = 2;
|
||||
repeated string conflicted_paths = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ChangeKind (var: TQd)
|
||||
enum ChangeKind {
|
||||
CHANGE_KIND_UNSPECIFIED = 0;
|
||||
CHANGE_KIND_ADDED = 1;
|
||||
CHANGE_KIND_DELETED = 2;
|
||||
CHANGE_KIND_MODIFIED = 3;
|
||||
CHANGE_KIND_RENAMED = 4;
|
||||
CHANGE_KIND_COPIED = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.Commit (var: azi)
|
||||
message Commit {
|
||||
string sha = 1;
|
||||
string message = 2;
|
||||
Signature author = 3;
|
||||
Signature committer = 4;
|
||||
repeated string parent_shas = 5;
|
||||
string tree_sha = 7;
|
||||
optional string change_id = 8;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CommitDiffChunk (var: rwv)
|
||||
message CommitDiffChunk {
|
||||
optional CommitDiffHeader header = 1;
|
||||
repeated DiffEntry entries = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CommitDiffHeader (var: iwv)
|
||||
message CommitDiffHeader {
|
||||
Commit commit = 1;
|
||||
optional string base_commit_sha = 2;
|
||||
CommitDiffStats stats = 3;
|
||||
bool has_more = 5;
|
||||
optional string next_page_cursor = 6;
|
||||
repeated DiffEntry entries = 7;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CommitDiffStats (var: owv)
|
||||
message CommitDiffStats {
|
||||
uint32 files_changed = 1;
|
||||
int32 additions = 2;
|
||||
int32 deletions = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CommitFileDelete (var: OSv)
|
||||
message CommitFileDelete {
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CommitFileMode (var: kSv)
|
||||
enum CommitFileMode {
|
||||
COMMIT_FILE_MODE_UNSPECIFIED = 0;
|
||||
COMMIT_FILE_MODE_REGULAR = 1;
|
||||
COMMIT_FILE_MODE_EXECUTABLE = 2;
|
||||
COMMIT_FILE_MODE_SYMLINK = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CommitFileOperation (var: FSv)
|
||||
message CommitFileOperation {
|
||||
string path = 1;
|
||||
oneof operation {
|
||||
CommitFileUpsert upsert = 2;
|
||||
CommitFileDelete delete = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CommitFileUpsert (var: NSv)
|
||||
message CommitFileUpsert {
|
||||
bytes content = 1;
|
||||
CommitFileMode mode = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CommitMetadata (var: xt)
|
||||
message CommitMetadata {
|
||||
string sha = 1;
|
||||
Signature author = 2;
|
||||
Signature committer = 3;
|
||||
string message = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CompareCommitsRequest (var: rn)
|
||||
message CompareCommitsRequest {
|
||||
string repo_uuid = 1;
|
||||
string base_revision = 2;
|
||||
string head_revision = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CompareCommitsResponse (var: PSv)
|
||||
message CompareCommitsResponse {
|
||||
CompareCommitsStatus status = 1;
|
||||
int32 ahead_by = 2;
|
||||
int32 behind_by = 3;
|
||||
string base_commit_sha = 4;
|
||||
string head_commit_sha = 5;
|
||||
string merge_base_commit_sha = 6;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CompareCommitsStatus (var: wSv)
|
||||
enum CompareCommitsStatus {
|
||||
COMPARE_COMMITS_STATUS_UNSPECIFIED = 0;
|
||||
COMPARE_COMMITS_STATUS_IDENTICAL = 1;
|
||||
COMPARE_COMMITS_STATUS_AHEAD = 2;
|
||||
COMPARE_COMMITS_STATUS_BEHIND = 3;
|
||||
COMPARE_COMMITS_STATUS_DIVERGED = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ComputeMergeCommitRequest (var: mn)
|
||||
message ComputeMergeCommitRequest {
|
||||
string repo_uuid = 1;
|
||||
string ours_sha = 2;
|
||||
string theirs_sha = 3;
|
||||
string message = 4;
|
||||
Signature author = 5;
|
||||
Signature committer = 6;
|
||||
MergeMode mode = 7;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ComputeMergeCommitResponse (var: cn)
|
||||
message ComputeMergeCommitResponse {
|
||||
string merge_commit_sha = 1;
|
||||
bytes packfile = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateBranchRequest (var: Qr)
|
||||
message CreateBranchRequest {
|
||||
string repo_uuid = 1;
|
||||
string target_ref = 2;
|
||||
string new_head_sha = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateBranchResponse (var: Gr)
|
||||
message CreateBranchResponse {
|
||||
string new_head_sha = 1;
|
||||
string wal_entry_key = 2;
|
||||
bool unchanged = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateCommitFromFilesRequest (var: En)
|
||||
message CreateCommitFromFilesRequest {
|
||||
string repo_uuid = 1;
|
||||
string target_ref = 2;
|
||||
optional string expected_head_sha = 3;
|
||||
string message = 4;
|
||||
Signature author = 5;
|
||||
optional Signature committer = 6;
|
||||
repeated CommitFileOperation files = 7;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateCommitFromFilesResponse (var: Sn)
|
||||
message CreateCommitFromFilesResponse {
|
||||
string commit_sha = 1;
|
||||
string tree_sha = 2;
|
||||
string old_head_sha = 3;
|
||||
string wal_entry_key = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateMergeCommitRequest (var: ln)
|
||||
message CreateMergeCommitRequest {
|
||||
string repo_uuid = 1;
|
||||
optional string ours_sha = 2;
|
||||
optional string theirs_sha = 3;
|
||||
string ours_ref = 4;
|
||||
string theirs_ref = 5;
|
||||
string message = 6;
|
||||
Signature author = 7;
|
||||
Signature committer = 8;
|
||||
uint64 change_number = 9;
|
||||
MergeMode mode = 10;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateMergeCommitResponse (var: un)
|
||||
message CreateMergeCommitResponse {
|
||||
string merge_commit_sha = 1;
|
||||
string wal_entry_key = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateRepoRequest (var: kr)
|
||||
message CreateRepoRequest {
|
||||
string repo_uuid = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateRepoResponse (var: wr)
|
||||
message CreateRepoResponse {
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateRevertBranchConflict (var: Jn)
|
||||
message CreateRevertBranchConflict {
|
||||
repeated string conflicted_paths = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateRevertBranchRequest (var: In)
|
||||
message CreateRevertBranchRequest {
|
||||
string repo_uuid = 1;
|
||||
string commit_sha = 2;
|
||||
string base_ref = 3;
|
||||
string branch_ref = 4;
|
||||
string message = 5;
|
||||
Signature author = 6;
|
||||
optional Signature committer = 7;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateRevertBranchResponse (var: vn)
|
||||
message CreateRevertBranchResponse {
|
||||
oneof result {
|
||||
CreateRevertBranchSuccess success = 1;
|
||||
CreateRevertBranchConflict conflict = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.CreateRevertBranchSuccess (var: Bn)
|
||||
message CreateRevertBranchSuccess {
|
||||
string revert_commit_sha = 1;
|
||||
string base_sha = 2;
|
||||
string wal_entry_key = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.DeleteBranchesRequest (var: Ur)
|
||||
message DeleteBranchesRequest {
|
||||
string repo_uuid = 1;
|
||||
repeated BranchDeletion branches = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.DeleteBranchesResponse (var: xr)
|
||||
message DeleteBranchesResponse {
|
||||
uint32 deleted_count = 1;
|
||||
uint32 missing_count = 2;
|
||||
string wal_entry_key = 3;
|
||||
bool unchanged = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.DiffEntry (var: czi)
|
||||
message DiffEntry {
|
||||
string path = 1;
|
||||
optional string old_path = 2;
|
||||
ChangeKind change_kind = 3;
|
||||
optional FileMode old_mode = 4;
|
||||
optional FileMode new_mode = 5;
|
||||
optional string old_sha = 6;
|
||||
optional string new_sha = 7;
|
||||
optional FileStats stats = 8;
|
||||
optional string patch = 9;
|
||||
optional bool is_generated = 10;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.DiffHeader (var: swv)
|
||||
message DiffHeader {
|
||||
string merge_base_commit_sha = 1;
|
||||
bool has_more = 4;
|
||||
optional string next_page_cursor = 5;
|
||||
repeated DiffEntry entries = 6;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.DirectoryContent (var: BSv)
|
||||
message DirectoryContent {
|
||||
repeated RepoContentEntry entries = 1;
|
||||
string sha = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.FastForwardRefRequest (var: Fr)
|
||||
message FastForwardRefRequest {
|
||||
string repo_uuid = 1;
|
||||
string target_ref = 2;
|
||||
string expected_head_sha = 3;
|
||||
string new_head_sha = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.FastForwardRefResponse (var: Dr)
|
||||
message FastForwardRefResponse {
|
||||
string old_head_sha = 1;
|
||||
string new_head_sha = 2;
|
||||
string wal_entry_key = 3;
|
||||
bool unchanged = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.FileContent (var: IQd)
|
||||
message FileContent {
|
||||
string size = 1;
|
||||
string encoding = 2;
|
||||
string content = 3;
|
||||
string sha = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.FileHistoryCommitEntry (var: HSv)
|
||||
message FileHistoryCommitEntry {
|
||||
ShortCommit commit = 1;
|
||||
optional string diff_base_commit_sha = 2;
|
||||
optional FileStats path_stats = 8;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.FileHistoryWithDiffStatsChunk (var: er)
|
||||
message FileHistoryWithDiffStatsChunk {
|
||||
repeated FileHistoryCommitEntry entries = 1;
|
||||
bool exhausted = 2;
|
||||
bool scan_truncated = 3;
|
||||
optional string resume_commit_sha = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.FileMode (var: xQd)
|
||||
enum FileMode {
|
||||
FILE_MODE_UNSPECIFIED = 0;
|
||||
FILE_MODE_REGULAR = 1;
|
||||
FILE_MODE_EXECUTABLE = 2;
|
||||
FILE_MODE_SYMLINK = 3;
|
||||
FILE_MODE_GITLINK = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.FileStats (var: DQd)
|
||||
message FileStats {
|
||||
int32 additions = 1;
|
||||
int32 deletions = 2;
|
||||
bool is_binary = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetBlameRequest (var: nr)
|
||||
message GetBlameRequest {
|
||||
string repo_uuid = 1;
|
||||
string start_commit_sha = 2;
|
||||
string path = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetBlobRequest (var: Ht)
|
||||
message GetBlobRequest {
|
||||
string repo_uuid = 1;
|
||||
string blob_sha = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetBlobResponse (var: xSv)
|
||||
message GetBlobResponse {
|
||||
FileContent blob = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetCommitDiffRequest (var: Ir)
|
||||
message GetCommitDiffRequest {
|
||||
string repo_uuid = 1;
|
||||
string commit_sha = 2;
|
||||
optional string base_commit_sha = 3;
|
||||
bool include_patches = 4;
|
||||
repeated string paths = 5;
|
||||
optional uint32 page_size = 6;
|
||||
optional string page_cursor = 7;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetCommitRequest (var: Dt)
|
||||
message GetCommitRequest {
|
||||
string repo_uuid = 1;
|
||||
string commit_sha = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetCommitResponse (var: ESv)
|
||||
message GetCommitResponse {
|
||||
Commit commit = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetDefaultBranchRequest (var: qn)
|
||||
message GetDefaultBranchRequest {
|
||||
string repo_uuid = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetDefaultBranchResponse (var: Fn)
|
||||
message GetDefaultBranchResponse {
|
||||
string default_branch = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetFileHistoryPageWithDiffStatsResponse (var: zSv)
|
||||
message GetFileHistoryPageWithDiffStatsResponse {
|
||||
repeated FileHistoryCommitEntry entries = 1;
|
||||
bool has_more = 2;
|
||||
optional string next_cursor = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetFileHistoryRequest (var: zn)
|
||||
message GetFileHistoryRequest {
|
||||
string repo_uuid = 1;
|
||||
string start_commit_sha = 2;
|
||||
optional string path = 3;
|
||||
uint32 max_commits = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetFileHistoryResponse (var: WSv)
|
||||
message GetFileHistoryResponse {
|
||||
repeated ShortCommit commits = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetFileHistoryWithDiffStatsRequest (var: Xn)
|
||||
message GetFileHistoryWithDiffStatsRequest {
|
||||
string repo_uuid = 1;
|
||||
string start_commit_sha = 2;
|
||||
optional string path = 3;
|
||||
uint32 max_commits = 4;
|
||||
optional string next_cursor = 5;
|
||||
bool include_diff_stats = 6;
|
||||
optional uint32 max_commits_scanned = 7;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetFileHistoryWithDiffStatsResponse (var: Zn)
|
||||
message GetFileHistoryWithDiffStatsResponse {
|
||||
repeated FileHistoryCommitEntry entries = 1;
|
||||
bool has_more = 2;
|
||||
optional string next_cursor = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetFuzzyPathsRequest (var: lr)
|
||||
message GetFuzzyPathsRequest {
|
||||
string repo_uuid = 1;
|
||||
string commit_sha = 2;
|
||||
string query = 3;
|
||||
uint32 limit = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetFuzzyPathsResponse (var: QSv)
|
||||
message GetFuzzyPathsResponse {
|
||||
repeated string paths = 1;
|
||||
bool has_more = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetLocalDevInfoRequest (var: qt)
|
||||
message GetLocalDevInfoRequest {
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetLocalDevInfoResponse (var: Ft)
|
||||
message GetLocalDevInfoResponse {
|
||||
string repo_uuid = 1;
|
||||
string git_forge_root_dir = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetPullRequestDiffRequest (var: Er)
|
||||
message GetPullRequestDiffRequest {
|
||||
string repo_uuid = 1;
|
||||
string head_commit_sha = 2;
|
||||
string base_commit_sha = 3;
|
||||
optional bool include_patches = 4;
|
||||
optional uint32 page_size = 5;
|
||||
optional string page_cursor = 6;
|
||||
optional bool include_file_stats = 7;
|
||||
optional bool include_generated = 8;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetRepoContentDetailsRequest (var: Kn)
|
||||
message GetRepoContentDetailsRequest {
|
||||
string repo_uuid = 1;
|
||||
PathIdentifier path_identifier = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetRepoContentDetailsResponse (var: jSv)
|
||||
message GetRepoContentDetailsResponse {
|
||||
optional RepoContentDetails details = 1;
|
||||
PathIdentifier path_identifier = 2;
|
||||
string resolved_commit_sha = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetRepoContentRequest (var: Dn)
|
||||
message GetRepoContentRequest {
|
||||
string repo_uuid = 1;
|
||||
optional uint64 max_file_size = 4;
|
||||
oneof id {
|
||||
PathIdentifier path_identifier = 2;
|
||||
string ref_and_path = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetRepoContentResponse (var: RQd)
|
||||
message GetRepoContentResponse {
|
||||
PathIdentifier path_identifier = 3;
|
||||
string resolved_commit_sha = 4;
|
||||
oneof content {
|
||||
FileContent file_content = 1;
|
||||
DirectoryContent directory_content = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetTagRequest (var: Yt)
|
||||
message GetTagRequest {
|
||||
string repo_uuid = 1;
|
||||
string tag_sha = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetTagResponse (var: TSv)
|
||||
message GetTagResponse {
|
||||
Tag tag = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetTreeBlameRequest (var: or)
|
||||
message GetTreeBlameRequest {
|
||||
string repo_uuid = 1;
|
||||
string start_commit_sha = 2;
|
||||
string path = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetTreeBlameResponse (var: KSv)
|
||||
message GetTreeBlameResponse {
|
||||
repeated TreeEntryBlame entries = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetTreeRequest (var: Wt)
|
||||
message GetTreeRequest {
|
||||
string repo_uuid = 1;
|
||||
string tree_sha = 2;
|
||||
bool recursive = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GetTreeResponse (var: ASv)
|
||||
message GetTreeResponse {
|
||||
Tree tree = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GrepLineKind (var: CSv)
|
||||
enum GrepLineKind {
|
||||
GREP_LINE_KIND_UNSPECIFIED = 0;
|
||||
GREP_LINE_KIND_MATCH = 1;
|
||||
GREP_LINE_KIND_CONTEXT = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GrepMatch (var: JSv)
|
||||
message GrepMatch {
|
||||
string path = 1;
|
||||
string lines = 2;
|
||||
uint32 line_number = 3;
|
||||
uint64 absolute_offset = 4;
|
||||
repeated GrepSubmatch submatches = 5;
|
||||
GrepLineKind kind = 6;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GrepRepoChunk (var: ewv)
|
||||
message GrepRepoChunk {
|
||||
repeated GrepMatch matches = 1;
|
||||
bool limit_hit = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GrepRepoRequest (var: pr)
|
||||
message GrepRepoRequest {
|
||||
string repo_uuid = 1;
|
||||
string revision = 2;
|
||||
string query = 3;
|
||||
GrepSearchOptions options = 4;
|
||||
uint32 max_results = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GrepSearchOptions (var: ZSv)
|
||||
message GrepSearchOptions {
|
||||
bool literal = 1;
|
||||
bool case_insensitive = 2;
|
||||
bool whole_word = 3;
|
||||
uint32 context_before = 4;
|
||||
uint32 context_after = 5;
|
||||
optional uint64 max_lines = 6;
|
||||
optional string filter_path = 7;
|
||||
repeated string includes = 8;
|
||||
repeated string excludes = 9;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.GrepSubmatch (var: XSv)
|
||||
message GrepSubmatch {
|
||||
uint32 start = 1;
|
||||
uint32 end = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListCommitsInRangeRequest (var: tn)
|
||||
message ListCommitsInRangeRequest {
|
||||
string repo_uuid = 1;
|
||||
string base_revision = 2;
|
||||
string head_revision = 3;
|
||||
optional int32 max_commits = 4;
|
||||
bool oldest_first = 5;
|
||||
ListCommitsSort sort = 6;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListCommitsInRangeResponse (var: MSv)
|
||||
message ListCommitsInRangeResponse {
|
||||
repeated Commit commits = 1;
|
||||
string base_commit_sha = 2;
|
||||
string head_commit_sha = 3;
|
||||
string merge_base_commit_sha = 4;
|
||||
bool truncated = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListCommitsRequest (var: Zt)
|
||||
message ListCommitsRequest {
|
||||
string repo_uuid = 1;
|
||||
string revision = 2;
|
||||
int32 page = 3;
|
||||
int32 per_page = 4;
|
||||
ListCommitsSort sort = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListCommitsResponse (var: en)
|
||||
message ListCommitsResponse {
|
||||
repeated Commit commits = 1;
|
||||
optional int32 next_page = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListCommitsSort (var: k)
|
||||
enum ListCommitsSort {
|
||||
LIST_COMMITS_SORT_UNSPECIFIED = 0;
|
||||
LIST_COMMITS_SORT_COMMIT_TIME = 1;
|
||||
LIST_COMMITS_SORT_TOPOLOGICAL = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListRefsFilter (var: AQd)
|
||||
enum ListRefsFilter {
|
||||
LIST_REFS_FILTER_UNSPECIFIED = 0;
|
||||
LIST_REFS_FILTER_ALL = 1;
|
||||
LIST_REFS_FILTER_BRANCHES = 2;
|
||||
LIST_REFS_FILTER_TAGS = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListRefsRequest (var: Pr)
|
||||
message ListRefsRequest {
|
||||
string repo_uuid = 1;
|
||||
ListRefsFilter filter = 2;
|
||||
bool names_only = 3;
|
||||
string prefix = 4;
|
||||
optional uint32 limit = 5;
|
||||
optional string page_token = 7;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListRefsResponse (var: awv)
|
||||
message ListRefsResponse {
|
||||
repeated string refs = 1;
|
||||
repeated RefInfo ref_infos = 2;
|
||||
optional string next_page_token = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListTreePathsRequest (var: mr)
|
||||
message ListTreePathsRequest {
|
||||
string repo_uuid = 1;
|
||||
string revision = 2;
|
||||
repeated string includes = 3;
|
||||
repeated string excludes = 4;
|
||||
uint32 limit = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ListTreePathsResponse (var: YSv)
|
||||
message ListTreePathsResponse {
|
||||
repeated string paths = 1;
|
||||
bool has_more = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.MergeMode (var: EQd)
|
||||
enum MergeMode {
|
||||
MERGE_MODE_UNSPECIFIED = 0;
|
||||
MERGE_MODE_MERGE_COMMIT = 1;
|
||||
MERGE_MODE_SQUASH = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.NotifyRepoPushedRequest (var: Ar)
|
||||
message NotifyRepoPushedRequest {
|
||||
string repo_uuid = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.NotifyRepoPushedResponse (var: _r)
|
||||
message NotifyRepoPushedResponse {
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.PathIdentifier (var: B$t)
|
||||
message PathIdentifier {
|
||||
string revision = 1;
|
||||
string path = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.PrepareChangeMergeRequest (var: dn)
|
||||
message PrepareChangeMergeRequest {
|
||||
string repo_uuid = 1;
|
||||
string base_ref = 2;
|
||||
string head_ref = 3;
|
||||
uint64 change_number = 4;
|
||||
optional string expected_base_sha = 5;
|
||||
optional string expected_head_sha = 6;
|
||||
MergeMode mode = 7;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.PrepareChangeMergeResponse (var: pn)
|
||||
message PrepareChangeMergeResponse {
|
||||
bool mergeable = 1;
|
||||
optional string merged_tree_sha = 2;
|
||||
optional string change_merge_ref = 3;
|
||||
optional string dummy_commit_sha = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.PullRequestDiffChunk (var: nwv)
|
||||
message PullRequestDiffChunk {
|
||||
optional DiffHeader header = 1;
|
||||
repeated DiffEntry entries = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RebaseStackBranch (var: gn)
|
||||
message RebaseStackBranch {
|
||||
string head_ref = 1;
|
||||
string expected_old_oid = 2;
|
||||
optional string replay_base_oid = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RebaseStackBranchUpdate (var: _n)
|
||||
message RebaseStackBranchUpdate {
|
||||
string head_ref = 1;
|
||||
string old_oid = 2;
|
||||
string new_oid = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RebaseStackConflict (var: Tn)
|
||||
message RebaseStackConflict {
|
||||
string conflicted_head_ref = 1;
|
||||
repeated string conflicted_paths = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RebaseStackRequest (var: fn)
|
||||
message RebaseStackRequest {
|
||||
string repo_uuid = 1;
|
||||
string onto_ref = 2;
|
||||
optional string expected_onto_oid = 3;
|
||||
repeated RebaseStackBranch branches = 4;
|
||||
bool dry_run = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RebaseStackResponse (var: hn)
|
||||
message RebaseStackResponse {
|
||||
oneof result {
|
||||
RebaseStackSuccess success = 1;
|
||||
RebaseStackConflict conflict = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RebaseStackSuccess (var: An)
|
||||
message RebaseStackSuccess {
|
||||
string wal_entry_key = 1;
|
||||
repeated RebaseStackBranchUpdate updates = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RefInfo (var: MQd)
|
||||
message RefInfo {
|
||||
string name = 1;
|
||||
string target_sha = 2;
|
||||
string object_sha = 3;
|
||||
string object_type = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RepoContentDetails (var: $Sv)
|
||||
message RepoContentDetails {
|
||||
string type = 1;
|
||||
optional uint64 size = 2;
|
||||
bool is_binary = 3;
|
||||
bool too_large_to_introspect = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.RepoContentEntry (var: twv)
|
||||
message RepoContentEntry {
|
||||
string type = 1;
|
||||
string name = 2;
|
||||
string path = 3;
|
||||
string sha = 4;
|
||||
optional uint64 size = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ResolveRefPathRequest (var: Mn)
|
||||
message ResolveRefPathRequest {
|
||||
string repo_uuid = 1;
|
||||
string ref_path = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ResolveRefPathResponse (var: USv)
|
||||
message ResolveRefPathResponse {
|
||||
PathIdentifier path_identifier = 1;
|
||||
string resolved_commit_sha = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.SearchRefsRequest (var: Lr)
|
||||
message SearchRefsRequest {
|
||||
string repo_uuid = 1;
|
||||
ListRefsFilter filter = 2;
|
||||
string query = 3;
|
||||
optional uint32 limit = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.SearchRefsResponse (var: cwv)
|
||||
message SearchRefsResponse {
|
||||
repeated RefInfo ref_infos = 1;
|
||||
bool exact_match = 2;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.ShortCommit (var: fMn)
|
||||
message ShortCommit {
|
||||
bytes sha = 1;
|
||||
string summary = 2;
|
||||
string author_name = 3;
|
||||
string author_email = 4;
|
||||
int64 timestamp = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.Signature (var: o_t)
|
||||
message Signature {
|
||||
string name = 1;
|
||||
string email = 2;
|
||||
int64 timestamp = 3;
|
||||
int32 timezone_offset = 4;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.Tag (var: DSv)
|
||||
message Tag {
|
||||
string sha = 1;
|
||||
string name = 2;
|
||||
string message = 3;
|
||||
Signature tagger = 4;
|
||||
string object_sha = 5;
|
||||
string object_type = 6;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.Tree (var: ISv)
|
||||
message Tree {
|
||||
string sha = 1;
|
||||
repeated TreeEntry tree = 2;
|
||||
bool truncated = 3;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.TreeEntry (var: RSv)
|
||||
message TreeEntry {
|
||||
string path = 1;
|
||||
string mode = 2;
|
||||
string type = 3;
|
||||
string sha = 4;
|
||||
optional uint64 size = 5;
|
||||
}
|
||||
|
||||
// Copied from: local:git_forge.v1.TreeEntryBlame (var: qSv)
|
||||
message TreeEntryBlame {
|
||||
string name = 1;
|
||||
ShortCommit last_commit = 2;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package internapi.v1;
|
||||
|
||||
option go_package = "github.com/leookun/cursor-byok/cursor-proto/gen/internapi/v1;internapiv1";
|
||||
|
||||
// Copied from: local:internapi.v1.BlobData (var: RLs)
|
||||
message BlobData {
|
||||
BlobType blob_type = 1;
|
||||
bytes blob_id = 2;
|
||||
int32 index = 3;
|
||||
oneof type_specific_data {
|
||||
ImageBlobData image_data = 4;
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from: local:internapi.v1.BlobDataPerMessage (var: ocu)
|
||||
message BlobDataPerMessage {
|
||||
repeated BlobData blob_data = 1;
|
||||
}
|
||||
|
||||
// Copied from: local:internapi.v1.BlobType (var: rcu)
|
||||
enum BlobType {
|
||||
BLOB_TYPE_UNSPECIFIED = 0;
|
||||
BLOB_TYPE_IMAGE = 1;
|
||||
BLOB_TYPE_INVOCATION_CONTEXT = 2;
|
||||
BLOB_TYPE_EXTRA_CONTEXT = 3;
|
||||
BLOB_TYPE_GIT_PR_DIFF_SELECTION = 4;
|
||||
BLOB_TYPE_SELECTED_PULL_REQUEST = 5;
|
||||
BLOB_TYPE_TEXT = 6;
|
||||
BLOB_TYPE_RICH_TEXT = 7;
|
||||
BLOB_TYPE_EXTERNAL_LINK_PDF = 8;
|
||||
BLOB_TYPE_DOCUMENT = 9;
|
||||
BLOB_TYPE_VIDEO = 10;
|
||||
}
|
||||
|
||||
// Copied from: local:internapi.v1.ImageBlobData (var: scu)
|
||||
message ImageBlobData {
|
||||
string mime_type = 1;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
use cursor_server::{App, Config, Result};
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| "cursor_server=info".into()),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
App::new(Config::from_env()?).await?.serve().await
|
||||
}
|
||||
@@ -695,7 +695,7 @@ fn estimate_output_tokens(output: &str) -> u64 {
|
||||
} else if output.is_empty() {
|
||||
0
|
||||
} else {
|
||||
((output.chars().count() as u64) + 3) / 4
|
||||
(output.chars().count() as u64).div_ceil(4)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -459,24 +459,36 @@ pub fn dynamic_mcp(
|
||||
Error::Protocol(format!("MCP tool {} is missing input schema", wire.name))
|
||||
})?),
|
||||
};
|
||||
let name = model_tool_name(&wire.name);
|
||||
let definition = ToolDefinition {
|
||||
name: wire.name.clone(),
|
||||
name: name.clone(),
|
||||
description: wire.description.clone(),
|
||||
parameters,
|
||||
};
|
||||
if output
|
||||
.insert(wire.name.clone(), (wire.clone(), definition))
|
||||
.insert(name.clone(), (wire.clone(), definition))
|
||||
.is_some()
|
||||
{
|
||||
return Err(Error::Protocol(format!(
|
||||
"duplicate MCP tool definition: {}",
|
||||
wire.name
|
||||
"duplicate MCP tool name after normalization: {name}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
fn model_tool_name(name: &str) -> String {
|
||||
name.chars()
|
||||
.map(|character| {
|
||||
if character.is_ascii_alphanumeric() || matches!(character, '_' | '-') {
|
||||
character
|
||||
} else {
|
||||
'_'
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn prost_value(value: &prost_types::Value) -> Value {
|
||||
use prost_types::value::Kind;
|
||||
match value.kind.as_ref() {
|
||||
@@ -511,6 +523,58 @@ fn xml(value: &str) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn direct_mcp_tool(name: &str) -> pb::McpToolDefinition {
|
||||
pb::McpToolDefinition {
|
||||
name: name.into(),
|
||||
provider_identifier: "extension-GitKraken".into(),
|
||||
tool_name: "git_status".into(),
|
||||
description: "Get repository status".into(),
|
||||
input_schema_json: Some(r#"{"type":"object"}"#.into()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dynamic_mcp_normalizes_extension_identifier_for_model_tool_names() {
|
||||
let original = "user-eamodio.gitlens-extension-GitKraken-git_status";
|
||||
let request = pb::AgentRunRequest {
|
||||
mcp_tools: Some(pb::McpTools {
|
||||
mcp_tools: vec![direct_mcp_tool(original)],
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let tools = dynamic_mcp(&request, &pb::RequestContext::default()).unwrap();
|
||||
let normalized = "user-eamodio_gitlens-extension-GitKraken-git_status";
|
||||
let (wire, definition) = tools.get(normalized).unwrap();
|
||||
|
||||
assert_eq!(definition.name, normalized);
|
||||
assert_eq!(wire.name, original);
|
||||
assert_eq!(wire.provider_identifier, "extension-GitKraken");
|
||||
assert_eq!(wire.tool_name, "git_status");
|
||||
assert!(normalized
|
||||
.chars()
|
||||
.all(|character| character.is_ascii_alphanumeric() || matches!(character, '_' | '-')));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dynamic_mcp_rejects_names_that_collide_after_normalization() {
|
||||
let request = pb::AgentRunRequest {
|
||||
mcp_tools: Some(pb::McpTools {
|
||||
mcp_tools: vec![
|
||||
direct_mcp_tool("server.name-tool"),
|
||||
direct_mcp_tool("server_name-tool"),
|
||||
],
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let error = dynamic_mcp(&request, &pb::RequestContext::default()).unwrap_err();
|
||||
assert!(error
|
||||
.to_string()
|
||||
.contains("duplicate MCP tool name after normalization: server_name-tool"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn meta_mcp_routes_projects_descriptor_routing_without_runtime_discovery() {
|
||||
let context = pb::RequestContext {
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
use super::{mcp_state, ReadImage, ToolCompletion};
|
||||
use super::{gate, mcp_state, ReadImage, ToolCompletion};
|
||||
use crate::cursor::tools::{
|
||||
edit,
|
||||
runtime::{ExecStage, PendingExec},
|
||||
@@ -18,6 +18,15 @@ pub(crate) fn from_exec(
|
||||
wire_result: &pb::exec_client_message::Message,
|
||||
) -> Result<ToolCompletion> {
|
||||
use pb::{exec_client_message::Message, tool_call::Tool};
|
||||
let mut gated_shell = matches!(
|
||||
wire_result,
|
||||
Message::ShellResult(_) | Message::MiniSweAgentBashResult(_)
|
||||
)
|
||||
.then(|| wire_result.clone());
|
||||
if let Some(message) = gated_shell.as_mut() {
|
||||
gate::exec_message(message);
|
||||
}
|
||||
let wire_result = gated_shell.as_ref().unwrap_or(wire_result);
|
||||
if let Message::McpStateExecResult(result) = wire_result {
|
||||
return mcp_state::complete(pending, result);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
use crate::cursor::proto::agent::v1 as pb;
|
||||
|
||||
const KIB: usize = 1024;
|
||||
const SHELL_STREAM_LIMIT: usize = 16 * KIB;
|
||||
const SHELL_CONTENT_LIMIT: usize = 32 * KIB;
|
||||
|
||||
pub(super) fn model_content(tool: &pb::tool_call::Tool, content: &mut String) {
|
||||
if matches!(tool, pb::tool_call::Tool::ShellToolCall(_)) {
|
||||
*content = truncate_edges("Shell", content, SHELL_CONTENT_LIMIT);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn exec_message(message: &mut pb::exec_client_message::Message) {
|
||||
use pb::exec_client_message::Message;
|
||||
match message {
|
||||
Message::ShellResult(result) | Message::MiniSweAgentBashResult(result) => {
|
||||
gate_shell_result(result)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn gate_shell_result(result: &mut pb::ShellResult) {
|
||||
use pb::shell_result::Result;
|
||||
match result.result.as_mut() {
|
||||
Some(Result::Success(success)) => {
|
||||
success.stdout = truncate_edges("Shell stdout", &success.stdout, SHELL_STREAM_LIMIT);
|
||||
success.stderr = truncate_edges("Shell stderr", &success.stderr, SHELL_STREAM_LIMIT);
|
||||
if let Some(interleaved) = success.interleaved_output.as_mut() {
|
||||
*interleaved =
|
||||
truncate_edges("Shell interleaved output", interleaved, SHELL_CONTENT_LIMIT);
|
||||
}
|
||||
}
|
||||
Some(Result::Failure(failure)) => {
|
||||
failure.stdout = truncate_edges("Shell stdout", &failure.stdout, SHELL_STREAM_LIMIT);
|
||||
failure.stderr = truncate_edges("Shell stderr", &failure.stderr, SHELL_STREAM_LIMIT);
|
||||
if let Some(interleaved) = failure.interleaved_output.as_mut() {
|
||||
*interleaved =
|
||||
truncate_edges("Shell interleaved output", interleaved, SHELL_CONTENT_LIMIT);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn truncate_edges(tool_name: &str, content: &str, limit: usize) -> String {
|
||||
if content.len() <= limit {
|
||||
return content.to_string();
|
||||
}
|
||||
let original = content.len();
|
||||
let mut shown = limit;
|
||||
loop {
|
||||
let notice = format!(
|
||||
"\n\n[truncated: {tool_name} result exceeded {limit} bytes; omitted middle; showing {shown} of {original} bytes]\n\n"
|
||||
);
|
||||
let available = limit.saturating_sub(notice.len());
|
||||
let head = utf8_prefix(content, available / 2);
|
||||
let tail = utf8_suffix(content, available.saturating_sub(head.len()));
|
||||
let next_shown = head.len().saturating_add(tail.len());
|
||||
if next_shown == shown {
|
||||
return format!("{head}{notice}{tail}");
|
||||
}
|
||||
shown = next_shown;
|
||||
}
|
||||
}
|
||||
|
||||
fn utf8_prefix(value: &str, limit: usize) -> &str {
|
||||
let mut end = limit.min(value.len());
|
||||
while end > 0 && !value.is_char_boundary(end) {
|
||||
end -= 1;
|
||||
}
|
||||
&value[..end]
|
||||
}
|
||||
|
||||
fn utf8_suffix(value: &str, limit: usize) -> &str {
|
||||
let mut start = value.len().saturating_sub(limit);
|
||||
while start < value.len() && !value.is_char_boundary(start) {
|
||||
start += 1;
|
||||
}
|
||||
&value[start..]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn shell_tool() -> pb::tool_call::Tool {
|
||||
pb::tool_call::Tool::ShellToolCall(pb::ShellToolCall::default())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_output_keeps_both_ends_within_its_budget() {
|
||||
let mut content = format!("HEAD{}TAIL", " ".repeat(1024 * KIB));
|
||||
|
||||
model_content(&shell_tool(), &mut content);
|
||||
|
||||
assert!(content.len() <= SHELL_CONTENT_LIMIT);
|
||||
assert!(content.starts_with("HEAD"));
|
||||
assert!(content.ends_with("TAIL"));
|
||||
assert!(content.contains("omitted middle"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_shell_output_is_unchanged() {
|
||||
let mut content = "x".repeat(64 * KIB);
|
||||
let original = content.clone();
|
||||
|
||||
model_content(
|
||||
&pb::tool_call::Tool::ReadToolCall(pb::ReadToolCall::default()),
|
||||
&mut content,
|
||||
);
|
||||
|
||||
assert_eq!(content, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_streams_are_limited_before_rendering() {
|
||||
let mut message = pb::exec_client_message::Message::ShellResult(pb::ShellResult {
|
||||
result: Some(pb::shell_result::Result::Success(pb::ShellSuccess {
|
||||
stdout: format!("HEAD{}TAIL", "x".repeat(64 * KIB)),
|
||||
stderr: format!("ERROR_HEAD{}ERROR_TAIL", "y".repeat(64 * KIB)),
|
||||
interleaved_output: Some(format!("START{}END", "z".repeat(64 * KIB))),
|
||||
..Default::default()
|
||||
})),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
exec_message(&mut message);
|
||||
|
||||
let pb::exec_client_message::Message::ShellResult(result) = message else {
|
||||
panic!("expected Shell result");
|
||||
};
|
||||
let Some(pb::shell_result::Result::Success(success)) = result.result else {
|
||||
panic!("expected Shell success");
|
||||
};
|
||||
assert!(success.stdout.len() <= SHELL_STREAM_LIMIT);
|
||||
assert!(success.stdout.starts_with("HEAD"));
|
||||
assert!(success.stdout.ends_with("TAIL"));
|
||||
assert!(success.stderr.len() <= SHELL_STREAM_LIMIT);
|
||||
assert!(success.stderr.starts_with("ERROR_HEAD"));
|
||||
assert!(success.stderr.ends_with("ERROR_TAIL"));
|
||||
assert!(success.interleaved_output.unwrap().len() <= SHELL_CONTENT_LIMIT);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_shell_streams_are_limited() {
|
||||
let mut message = pb::exec_client_message::Message::ShellResult(pb::ShellResult {
|
||||
result: Some(pb::shell_result::Result::Failure(pb::ShellFailure {
|
||||
stdout: "x".repeat(64 * KIB),
|
||||
stderr: "y".repeat(64 * KIB),
|
||||
interleaved_output: Some("z".repeat(64 * KIB)),
|
||||
..Default::default()
|
||||
})),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
exec_message(&mut message);
|
||||
|
||||
let pb::exec_client_message::Message::ShellResult(result) = message else {
|
||||
panic!("expected Shell result");
|
||||
};
|
||||
let Some(pb::shell_result::Result::Failure(failure)) = result.result else {
|
||||
panic!("expected Shell failure");
|
||||
};
|
||||
assert!(failure.stdout.len() <= SHELL_STREAM_LIMIT);
|
||||
assert!(failure.stderr.len() <= SHELL_STREAM_LIMIT);
|
||||
assert!(failure.interleaved_output.unwrap().len() <= SHELL_CONTENT_LIMIT);
|
||||
}
|
||||
}
|
||||
@@ -169,6 +169,13 @@ fn text(value: &Value, name: &str) -> String {
|
||||
.into()
|
||||
}
|
||||
|
||||
fn normalized(name: &str) -> String {
|
||||
name.chars()
|
||||
.filter(|character| character.is_ascii_alphanumeric())
|
||||
.flat_map(char::to_lowercase)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -203,10 +210,3 @@ mod tests {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn normalized(name: &str) -> String {
|
||||
name.chars()
|
||||
.filter(|character| character.is_ascii_alphanumeric())
|
||||
.flat_map(char::to_lowercase)
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
mod await_shell;
|
||||
mod exec;
|
||||
mod gate;
|
||||
mod interaction;
|
||||
mod local;
|
||||
mod mcp;
|
||||
@@ -87,9 +88,10 @@ impl ToolCompletion {
|
||||
pub(crate) fn new(
|
||||
call: &ToolCall,
|
||||
started_at_ms: u64,
|
||||
result: ToolResult,
|
||||
mut result: ToolResult,
|
||||
tool: pb::tool_call::Tool,
|
||||
) -> Self {
|
||||
gate::model_content(&tool, &mut result.content);
|
||||
Self {
|
||||
result,
|
||||
tool_call: pb::ToolCall {
|
||||
|
||||
@@ -346,6 +346,13 @@ impl CursorToolRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn now_ms() -> u64 {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis() as u64
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -420,10 +427,3 @@ mod tests {
|
||||
.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn now_ms() -> u64 {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis() as u64
|
||||
}
|
||||
|
||||
@@ -138,7 +138,12 @@ pub fn normalize_base_url(value: &str) -> Result<String> {
|
||||
Ok(url.as_str().trim_end_matches('/').to_string())
|
||||
}
|
||||
|
||||
pub fn model_hash(base_url: &str, provider_type: ProviderType, model_id: &str) -> Result<String> {
|
||||
pub fn model_hash(
|
||||
base_url: &str,
|
||||
api_key: &str,
|
||||
provider_type: ProviderType,
|
||||
model_id: &str,
|
||||
) -> Result<String> {
|
||||
let base_url = normalize_base_url(base_url)?;
|
||||
let model_id = model_id.trim();
|
||||
if model_id.is_empty() {
|
||||
@@ -147,6 +152,8 @@ pub fn model_hash(base_url: &str, provider_type: ProviderType, model_id: &str) -
|
||||
let mut digest = Sha256::new();
|
||||
digest.update(base_url.as_bytes());
|
||||
digest.update([0]);
|
||||
digest.update(api_key.as_bytes());
|
||||
digest.update([0]);
|
||||
digest.update(provider_type.as_str().as_bytes());
|
||||
digest.update([0]);
|
||||
digest.update(model_id.as_bytes());
|
||||
@@ -212,24 +219,41 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn hash_uses_normalized_url_type_and_model_only() {
|
||||
fn hash_uses_normalized_url_key_type_and_model() {
|
||||
let first = model_hash(
|
||||
"HTTPS://Example.COM/v1/",
|
||||
"secret",
|
||||
ProviderType::OpenAiChat,
|
||||
"model-a",
|
||||
)
|
||||
.unwrap();
|
||||
let second = model_hash(
|
||||
"https://example.com/v1",
|
||||
"secret",
|
||||
ProviderType::OpenAiChat,
|
||||
"model-a",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(first, second);
|
||||
assert_eq!(first, "f246010a");
|
||||
assert_ne!(
|
||||
first,
|
||||
model_hash("https://example.com/v1", ProviderType::Anthropic, "model-a").unwrap()
|
||||
model_hash(
|
||||
"https://example.com/v1",
|
||||
"different-secret",
|
||||
ProviderType::OpenAiChat,
|
||||
"model-a",
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
assert_ne!(
|
||||
first,
|
||||
model_hash(
|
||||
"https://example.com/v1",
|
||||
"secret",
|
||||
ProviderType::Anthropic,
|
||||
"model-a",
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,12 @@ struct ResponseToolState {
|
||||
ended: bool,
|
||||
}
|
||||
|
||||
enum ResponseToolArguments<'a> {
|
||||
None,
|
||||
Delta(&'a str),
|
||||
Snapshot(&'a str),
|
||||
}
|
||||
|
||||
pub struct OpenAiResponsesProvider {
|
||||
client: reqwest::Client,
|
||||
config: ProviderConfig,
|
||||
@@ -152,7 +158,7 @@ impl Provider for OpenAiResponsesProvider {
|
||||
if item.get("type").and_then(Value::as_str) == Some("function_call") {
|
||||
let index = required_u64(&value, "output_index")? as usize;
|
||||
saw_tool = true;
|
||||
for event in update_response_tool(index, item, None, false, &mut tools)? { yield event; }
|
||||
for event in update_response_tool(index, item, ResponseToolArguments::None, false, &mut tools)? { yield event; }
|
||||
}
|
||||
}
|
||||
"response.output_item.done" => {
|
||||
@@ -172,8 +178,11 @@ impl Provider for OpenAiResponsesProvider {
|
||||
Some("function_call") => {
|
||||
let index = required_u64(&value, "output_index")? as usize;
|
||||
saw_tool = true;
|
||||
let final_arguments = item.get("arguments").and_then(Value::as_str);
|
||||
for event in update_response_tool(index, item, final_arguments, true, &mut tools)? { yield event; }
|
||||
let arguments = item
|
||||
.get("arguments")
|
||||
.and_then(Value::as_str)
|
||||
.map_or(ResponseToolArguments::None, ResponseToolArguments::Snapshot);
|
||||
for event in update_response_tool(index, item, arguments, true, &mut tools)? { yield event; }
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -182,39 +191,19 @@ impl Provider for OpenAiResponsesProvider {
|
||||
let index = required_u64(&value, "output_index")? as usize;
|
||||
if let Some(delta) = value.get("delta").and_then(Value::as_str) {
|
||||
saw_tool = true;
|
||||
for event in update_response_tool(index, &Value::Null, Some(delta), false, &mut tools)? { yield event; }
|
||||
for event in update_response_tool(index, &Value::Null, ResponseToolArguments::Delta(delta), false, &mut tools)? { yield event; }
|
||||
}
|
||||
}
|
||||
"response.function_call_arguments.done" => {
|
||||
let index = required_u64(&value, "output_index")? as usize;
|
||||
let final_arguments = value.get("arguments").and_then(Value::as_str);
|
||||
for event in update_response_tool(index, &Value::Null, final_arguments, true, &mut tools)? { yield event; }
|
||||
let arguments = value
|
||||
.get("arguments")
|
||||
.and_then(Value::as_str)
|
||||
.map_or(ResponseToolArguments::None, ResponseToolArguments::Snapshot);
|
||||
for event in update_response_tool(index, &Value::Null, arguments, true, &mut tools)? { yield event; }
|
||||
}
|
||||
"response.completed" => {
|
||||
if let Some(usage) = value.pointer("/response/usage") { yield ModelEvent::Usage(responses_usage(usage)); }
|
||||
if let Some(output) = value.pointer("/response/output").and_then(Value::as_array) {
|
||||
for (index, item) in output.iter().enumerate() {
|
||||
match item.get("type").and_then(Value::as_str) {
|
||||
Some("reasoning") => {
|
||||
if thinking_open { thinking_open = false; yield ModelEvent::ThinkingEnd; }
|
||||
if !reasoning_items.iter().any(|existing| existing.get("id") == item.get("id")) {
|
||||
reasoning_items.push(item.clone());
|
||||
}
|
||||
}
|
||||
Some("message") => {
|
||||
if let Some(final_text) = response_item_text(item) {
|
||||
for event in reconcile_response_text(&mut text_open, &mut text, &final_text) { yield event; }
|
||||
}
|
||||
}
|
||||
Some("function_call") => {
|
||||
saw_tool = true;
|
||||
let final_arguments = item.get("arguments").and_then(Value::as_str);
|
||||
for event in update_response_tool(index, item, final_arguments, true, &mut tools)? { yield event; }
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
if thinking_open { thinking_open = false; yield ModelEvent::ThinkingEnd; }
|
||||
if text_open { text_open = false; yield ModelEvent::TextEnd; }
|
||||
for (index, tool) in tools.iter_mut().filter(|(_, tool)| tool.started && !tool.ended) {
|
||||
@@ -303,7 +292,7 @@ fn reconcile_response_text(
|
||||
fn update_response_tool(
|
||||
index: usize,
|
||||
item: &Value,
|
||||
arguments: Option<&str>,
|
||||
arguments: ResponseToolArguments<'_>,
|
||||
done: bool,
|
||||
tools: &mut std::collections::BTreeMap<usize, ResponseToolState>,
|
||||
) -> Result<Vec<ModelEvent>> {
|
||||
@@ -314,11 +303,17 @@ fn update_response_tool(
|
||||
if let Some(name) = item.get("name").and_then(Value::as_str) {
|
||||
tool.name.get_or_insert_with(|| name.into());
|
||||
}
|
||||
if let Some(arguments) = arguments {
|
||||
if arguments.starts_with(&tool.arguments) {
|
||||
tool.arguments.push_str(&arguments[tool.arguments.len()..]);
|
||||
} else if !tool.arguments.ends_with(arguments) {
|
||||
tool.arguments.push_str(arguments);
|
||||
match arguments {
|
||||
ResponseToolArguments::None => {}
|
||||
ResponseToolArguments::Delta(delta) => tool.arguments.push_str(delta),
|
||||
ResponseToolArguments::Snapshot(snapshot) if snapshot == tool.arguments => {}
|
||||
ResponseToolArguments::Snapshot(snapshot) if snapshot.starts_with(&tool.arguments) => {
|
||||
tool.arguments.push_str(&snapshot[tool.arguments.len()..]);
|
||||
}
|
||||
ResponseToolArguments::Snapshot(_) => {
|
||||
return Err(Error::Provider(
|
||||
"OpenAI Responses final tool arguments do not match streamed arguments".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,6 +448,7 @@ fn responses_content(parts: &[ContentPart], text_type: &str) -> Result<Vec<Value
|
||||
ContentPart::Text { text } => Some(Ok(json!({"type":text_type, "text":text}))),
|
||||
ContentPart::Image { mime_type, data } => Some(Ok(json!({
|
||||
"type":"input_image",
|
||||
"detail":"auto",
|
||||
"image_url":format!("data:{mime_type};base64,{}", STANDARD.encode(data)),
|
||||
}))),
|
||||
})
|
||||
@@ -508,8 +504,11 @@ fn responses_usage(value: &Value) -> Usage {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::responses_input;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use super::{responses_input, update_response_tool, ResponseToolArguments, ResponseToolState};
|
||||
use crate::model::{ContentPart, ProjectedContent, ProjectedMessage, Role, ToolResultContent};
|
||||
use crate::provider::ModelEvent;
|
||||
|
||||
#[test]
|
||||
fn read_image_stays_in_its_function_call_output() {
|
||||
@@ -539,5 +538,73 @@ mod tests {
|
||||
assert_eq!(input[0]["call_id"], "call");
|
||||
assert_eq!(input[0]["output"][0]["type"], "input_text");
|
||||
assert_eq!(input[0]["output"][1]["type"], "input_image");
|
||||
assert_eq!(input[0]["output"][1]["detail"], "auto");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_argument_deltas_are_ordered_bytes_and_final_snapshots_are_idempotent() {
|
||||
let item = serde_json::json!({"call_id": "call-1", "name": "Shell"});
|
||||
let mut tools = BTreeMap::<usize, ResponseToolState>::new();
|
||||
let mut events = update_response_tool(
|
||||
0,
|
||||
&item,
|
||||
ResponseToolArguments::Delta(r#"{"block_until_ms":300"#),
|
||||
false,
|
||||
&mut tools,
|
||||
)
|
||||
.unwrap();
|
||||
events.extend(
|
||||
update_response_tool(
|
||||
0,
|
||||
&item,
|
||||
ResponseToolArguments::Delta("00"),
|
||||
false,
|
||||
&mut tools,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
events.extend(
|
||||
update_response_tool(
|
||||
0,
|
||||
&item,
|
||||
ResponseToolArguments::Delta("}"),
|
||||
false,
|
||||
&mut tools,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
events.extend(
|
||||
update_response_tool(
|
||||
0,
|
||||
&item,
|
||||
ResponseToolArguments::Snapshot(r#"{"block_until_ms":30000}"#),
|
||||
true,
|
||||
&mut tools,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let arguments = events
|
||||
.iter()
|
||||
.filter_map(|event| match event {
|
||||
ModelEvent::ToolCallArgumentsDelta { delta, .. } => Some(delta.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<String>();
|
||||
assert_eq!(arguments, r#"{"block_until_ms":30000}"#);
|
||||
assert_eq!(
|
||||
serde_json::from_str::<serde_json::Value>(&arguments).unwrap()["block_until_ms"],
|
||||
30000
|
||||
);
|
||||
|
||||
assert!(update_response_tool(
|
||||
0,
|
||||
&item,
|
||||
ResponseToolArguments::Snapshot(r#"{"block_until_ms":30000}"#),
|
||||
true,
|
||||
&mut tools,
|
||||
)
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,12 @@ impl Store {
|
||||
let mut hashes = Vec::with_capacity(models.len());
|
||||
let mut unique_hashes = HashSet::with_capacity(models.len());
|
||||
for model in models {
|
||||
let hash = model_hash(&base_url, model.endpoint_type, &model.model_id)?;
|
||||
let hash = model_hash(
|
||||
&base_url,
|
||||
provider.api_key.as_deref().unwrap_or_default(),
|
||||
model.endpoint_type,
|
||||
&model.model_id,
|
||||
)?;
|
||||
if !unique_hashes.insert(hash.clone()) {
|
||||
return Err(Error::Config(format!(
|
||||
"8-character model hash collision: {hash}"
|
||||
@@ -125,8 +130,8 @@ impl Store {
|
||||
let api_key = input.api_key.as_deref().unwrap_or(¤t.api_key);
|
||||
let custom_headers = merge_custom_headers(¤t.custom_headers, &input.custom_headers)?;
|
||||
let base_url = normalize_base_url(&input.base_url)?;
|
||||
let base_url_changed = base_url != current.endpoint.base_url;
|
||||
let models = if base_url_changed {
|
||||
let identity_changed = base_url != current.endpoint.base_url || api_key != current.api_key;
|
||||
let models = if identity_changed {
|
||||
sqlx::query("SELECT * FROM provider_models WHERE provider_id = ?")
|
||||
.bind(provider_id)
|
||||
.fetch_all(&self.pool)
|
||||
@@ -140,7 +145,7 @@ impl Store {
|
||||
let mut next_hashes = Vec::with_capacity(models.len());
|
||||
let mut unique_hashes = HashSet::with_capacity(models.len());
|
||||
for model in &models {
|
||||
let hash = model_hash(&base_url, model.endpoint_type, &model.model_id)?;
|
||||
let hash = model_hash(&base_url, api_key, model.endpoint_type, &model.model_id)?;
|
||||
if !unique_hashes.insert(hash.clone()) {
|
||||
return Err(Error::Config(format!(
|
||||
"8-character model hash collision: {hash}"
|
||||
@@ -271,6 +276,7 @@ impl Store {
|
||||
for input in inputs {
|
||||
let hash = model_hash(
|
||||
&provider.endpoint.base_url,
|
||||
&provider.api_key,
|
||||
input.endpoint_type,
|
||||
&input.model_id,
|
||||
)?;
|
||||
@@ -327,6 +333,7 @@ impl Store {
|
||||
.expect("model provider must exist");
|
||||
let next_hash = model_hash(
|
||||
&provider.endpoint.base_url,
|
||||
&provider.api_key,
|
||||
input.endpoint_type,
|
||||
&input.model_id,
|
||||
)?;
|
||||
@@ -680,6 +687,33 @@ mod tests {
|
||||
assert_eq!(store.provider_models(false).await.unwrap().len(), 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn allows_same_endpoint_and_model_with_different_api_keys() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let store = Store::connect(&format!(
|
||||
"sqlite://{}",
|
||||
directory.path().join("credential-models.db").display()
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
let first_provider = provider();
|
||||
let mut second_provider = provider();
|
||||
second_provider.name = "Second".into();
|
||||
second_provider.api_key = Some("different-secret".into());
|
||||
|
||||
let (_, first_model) = store
|
||||
.create_provider_with_model(&first_provider, &model("model-a"))
|
||||
.await
|
||||
.unwrap();
|
||||
let (_, second_model) = store
|
||||
.create_provider_with_model(&second_provider, &model("model-a"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_ne!(first_model.model_hash, second_model.model_hash);
|
||||
assert_eq!(store.provider_models(false).await.unwrap().len(), 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn adds_multiple_models_to_existing_provider_atomically() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
@@ -750,6 +784,55 @@ mod tests {
|
||||
models[0].model_hash,
|
||||
model_hash(
|
||||
&updated_provider.base_url,
|
||||
input.api_key.as_deref().unwrap(),
|
||||
models[0].endpoint_type,
|
||||
&models[0].model_id,
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
let detached: Option<String> =
|
||||
sqlx::query_scalar("SELECT model_hash FROM llm_calls WHERE call_id = ?")
|
||||
.bind("call-1")
|
||||
.fetch_one(store.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(detached, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn updating_provider_api_key_rehashes_its_models() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let store = Store::connect(&format!(
|
||||
"sqlite://{}",
|
||||
directory.path().join("provider-key-update.db").display()
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
let (created_provider, original) = store
|
||||
.create_provider_with_model(&provider(), &model("model-a"))
|
||||
.await
|
||||
.unwrap();
|
||||
insert_call(&store, &created_provider, &original).await;
|
||||
|
||||
let mut input = provider();
|
||||
input.api_key = Some("different-secret".into());
|
||||
store
|
||||
.update_provider(created_provider.provider_id, &input)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(store
|
||||
.provider_model(&original.model_hash)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
let models = store.provider_models(false).await.unwrap();
|
||||
assert_eq!(models.len(), 1);
|
||||
assert_eq!(
|
||||
models[0].model_hash,
|
||||
model_hash(
|
||||
&created_provider.base_url,
|
||||
"different-secret",
|
||||
models[0].endpoint_type,
|
||||
&models[0].model_id,
|
||||
)
|
||||
|
||||
@@ -77,7 +77,7 @@ async fn provider_secret_is_write_only_and_model_hash_is_stable() {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(model.model_hash, "f246010a");
|
||||
assert_eq!(model.model_hash, "bab5019a");
|
||||
assert!(model.supports_image_generation);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +148,35 @@ async fn duplicate_usage_is_rejected_instead_of_guessing_which_total_is_final()
|
||||
assert!(matches!(failure.failure, RunFailure::Protocol(_)));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn duplicate_tool_call_ids_are_rejected_across_distinct_indexes() {
|
||||
let (sender, _receiver) = tokio::sync::mpsc::channel(8);
|
||||
let failure = consume_model_cycle(
|
||||
provider_stream(vec![
|
||||
ModelEvent::Start {
|
||||
model_call_id: "model-call".into(),
|
||||
},
|
||||
ModelEvent::ToolCallStart {
|
||||
index: 0,
|
||||
call_id: "call-1".into(),
|
||||
name: "Read".into(),
|
||||
},
|
||||
ModelEvent::ToolCallEnd { index: 0 },
|
||||
ModelEvent::ToolCallStart {
|
||||
index: 1,
|
||||
call_id: "call-1".into(),
|
||||
name: "Read".into(),
|
||||
},
|
||||
]),
|
||||
&sender,
|
||||
&CancellationToken::new(),
|
||||
)
|
||||
.await
|
||||
.unwrap_err();
|
||||
|
||||
assert!(matches!(failure.failure, RunFailure::Protocol(_)));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn openai_chat_raw_stream_and_request_projection_match_the_endpoint() {
|
||||
let (base_url, mut requests, server) = fixture_server(
|
||||
@@ -305,6 +334,7 @@ async fn openai_responses_raw_stream_does_not_invent_reasoning_effort() {
|
||||
assert!(body.get("service_tier").is_none());
|
||||
assert_eq!(body["max_output_tokens"], 4096);
|
||||
assert_eq!(body["input"][0]["content"][1]["type"], "input_image");
|
||||
assert_eq!(body["input"][0]["content"][1]["detail"], "auto");
|
||||
assert_eq!(
|
||||
body["input"][0]["content"][1]["image_url"],
|
||||
"data:image/png;base64,AQID"
|
||||
@@ -424,12 +454,47 @@ async fn openai_responses_item_done_closes_text_and_tool_arguments() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn openai_responses_completed_object_recovers_missing_item_events() {
|
||||
async fn openai_responses_preserves_delta_that_repeats_the_streamed_suffix() {
|
||||
let (base_url, _requests, server) = fixture_server(
|
||||
"/v1/responses",
|
||||
concat!(
|
||||
"data: {\"type\":\"response.output_item.added\",\"output_index\":0,\"item\":{\"type\":\"function_call\",\"call_id\":\"call-1\",\"name\":\"Shell\"}}\n\n",
|
||||
"data: {\"type\":\"response.function_call_arguments.delta\",\"output_index\":0,\"delta\":\"{\\\"block_until_ms\\\":300\"}\n\n",
|
||||
"data: {\"type\":\"response.function_call_arguments.delta\",\"output_index\":0,\"delta\":\"00\"}\n\n",
|
||||
"data: {\"type\":\"response.function_call_arguments.delta\",\"output_index\":0,\"delta\":\"}\"}\n\n",
|
||||
"data: {\"type\":\"response.function_call_arguments.done\",\"output_index\":0,\"arguments\":\"{\\\"block_until_ms\\\":30000}\"}\n\n",
|
||||
"data: {\"type\":\"response.output_item.done\",\"output_index\":0,\"item\":{\"type\":\"function_call\",\"call_id\":\"call-1\",\"name\":\"Shell\",\"arguments\":\"{\\\"block_until_ms\\\":30000}\"}}\n\n",
|
||||
"data: {\"type\":\"response.completed\",\"response\":{}}\n\n",
|
||||
),
|
||||
)
|
||||
.await;
|
||||
let provider = OpenAiResponsesProvider::new(
|
||||
reqwest::Client::new(),
|
||||
config(ProviderKind::OpenAiResponses, base_url, None),
|
||||
);
|
||||
let (sender, _receiver) = tokio::sync::mpsc::channel(32);
|
||||
|
||||
let result = consume_model_cycle(
|
||||
provider.stream(invocation(), CancellationToken::new()),
|
||||
&sender,
|
||||
&CancellationToken::new(),
|
||||
)
|
||||
.await;
|
||||
server.abort();
|
||||
|
||||
assert_eq!(result.unwrap().calls[0].arguments["block_until_ms"], 30000);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn openai_responses_completed_snapshot_does_not_reindex_streamed_tool() {
|
||||
let (base_url, _requests, server) = fixture_server(
|
||||
"/v1/responses",
|
||||
concat!(
|
||||
"data: {\"type\":\"response.output_item.done\",\"output_index\":0,\"item\":{\"type\":\"reasoning\",\"id\":\"reasoning-1\",\"encrypted_content\":\"opaque\"}}\n\n",
|
||||
"data: {\"type\":\"response.output_item.added\",\"output_index\":1,\"item\":{\"type\":\"function_call\",\"call_id\":\"call-1\",\"name\":\"Read\"}}\n\n",
|
||||
"data: {\"type\":\"response.function_call_arguments.done\",\"output_index\":1,\"arguments\":\"{\\\"path\\\":\\\"a\\\"}\"}\n\n",
|
||||
"data: {\"type\":\"response.output_item.done\",\"output_index\":1,\"item\":{\"type\":\"function_call\",\"call_id\":\"call-1\",\"name\":\"Read\",\"arguments\":\"{\\\"path\\\":\\\"a\\\"}\"}}\n\n",
|
||||
"data: {\"type\":\"response.completed\",\"response\":{\"output\":[",
|
||||
"{\"type\":\"message\",\"content\":[{\"type\":\"output_text\",\"text\":\"ok\"}]},",
|
||||
"{\"type\":\"function_call\",\"call_id\":\"call-1\",\"name\":\"Read\",\"arguments\":\"{\\\"path\\\":\\\"a\\\"}\"}",
|
||||
"]}}\n\n",
|
||||
),
|
||||
@@ -439,18 +504,21 @@ async fn openai_responses_completed_object_recovers_missing_item_events() {
|
||||
reqwest::Client::new(),
|
||||
config(ProviderKind::OpenAiResponses, base_url, None),
|
||||
);
|
||||
let (sender, _receiver) = tokio::sync::mpsc::channel(32);
|
||||
|
||||
let events = collect(provider.stream(invocation(), CancellationToken::new())).await;
|
||||
let cycle = consume_model_cycle(
|
||||
provider.stream(invocation(), CancellationToken::new()),
|
||||
&sender,
|
||||
&CancellationToken::new(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
server.abort();
|
||||
|
||||
assert!(events
|
||||
.iter()
|
||||
.any(|event| matches!(event, ModelEvent::TextDelta(text) if text == "ok")));
|
||||
assert!(events.iter().any(|event| matches!(event, ModelEvent::ToolCallStart { call_id, name, .. } if call_id == "call-1" && name == "Read")));
|
||||
assert_eq!(
|
||||
events.last(),
|
||||
Some(&ModelEvent::Done(FinishReason::ToolUse))
|
||||
);
|
||||
assert_eq!(cycle.calls.len(), 1);
|
||||
assert_eq!(cycle.calls[0].index, 1);
|
||||
assert_eq!(cycle.calls[0].call_id, "call-1");
|
||||
assert_eq!(cycle.calls[0].arguments["path"], "a");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -16,10 +16,7 @@ use cursor_server::{
|
||||
#[test]
|
||||
fn task_keeps_wire_type_model_parent_and_background_fields() {
|
||||
let mut context = context();
|
||||
context.subagent_models.insert(
|
||||
"cursor-guide".into(),
|
||||
SubagentModel::Model("guide-model".into()),
|
||||
);
|
||||
context.subagent_model = Some(SubagentModel::Model("guide-model".into()));
|
||||
let call = task_call(serde_json::json!({
|
||||
"description": "guide",
|
||||
"prompt": "inspect",
|
||||
@@ -105,9 +102,7 @@ fn task_renders_general_typed_and_custom_subagent_types_without_aliases() {
|
||||
#[test]
|
||||
fn disabled_task_model_is_left_for_the_model_visible_reminder() {
|
||||
let mut context = context();
|
||||
context
|
||||
.subagent_models
|
||||
.insert("security-review".into(), SubagentModel::Disabled);
|
||||
context.subagent_model = Some(SubagentModel::Disabled);
|
||||
let call = task_call(serde_json::json!({
|
||||
"description": "review",
|
||||
"prompt": "inspect",
|
||||
@@ -192,7 +187,7 @@ fn context() -> ExecContext {
|
||||
conversation_id: "child".into(),
|
||||
root_conversation_id: "root".into(),
|
||||
default_subagent_model: "parent-model".into(),
|
||||
subagent_models: HashMap::new(),
|
||||
subagent_model: None,
|
||||
allow_subagents: true,
|
||||
subagents_disabled: false,
|
||||
terminals_folder: "/tmp/terminals".into(),
|
||||
|
||||
@@ -42,7 +42,7 @@ fn exec_context() -> ExecContext {
|
||||
conversation_id: "conversation".into(),
|
||||
root_conversation_id: "conversation".into(),
|
||||
default_subagent_model: "model".into(),
|
||||
subagent_models: std::collections::HashMap::new(),
|
||||
subagent_model: None,
|
||||
terminals_folder: "/tmp/terminals".into(),
|
||||
admin_command_denylist: Vec::new(),
|
||||
allow_subagents: true,
|
||||
|
||||
Reference in New Issue
Block a user