branchora-sdk 1.0.0 → 1.1.0
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/README.md +15 -4
- package/dist/index.js +431 -100
- package/package.json +1 -1
- package/types/core/agent-identity.d.ts +12 -0
- package/types/sdk/client.d.ts +50 -13
- package/types/sdk/index.d.ts +4 -1
- package/types/sdk/types.d.ts +155 -0
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const AGENT_CAPABILITIES: readonly ["git:read", "git:write", "git:review", "git:merge", "git:check", "execution:read", "execution:write"];
|
|
2
|
+
export type AgentCapability = (typeof AGENT_CAPABILITIES)[number];
|
|
3
|
+
export interface AgentIdentity {
|
|
4
|
+
agentId: string;
|
|
5
|
+
credentialId: string;
|
|
6
|
+
projectId: string;
|
|
7
|
+
capabilities: AgentCapability[];
|
|
8
|
+
writeBranches: string[];
|
|
9
|
+
generation: number;
|
|
10
|
+
}
|
|
11
|
+
/** Only a trailing wildcard is supported; no regular expressions are accepted from callers. */
|
|
12
|
+
export declare function matchesAgentBranch(branch: string, patterns: readonly string[]): boolean;
|
package/types/sdk/client.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ContextBlock, Provider, TraceEvent } from '../core/types.js';
|
|
2
|
+
import { type AgentIdentity } from '../core/agent-identity.js';
|
|
3
|
+
import type { AgentAccessOptions, AgentAccessRecord, AgentCredentialRecord, AgentSession, ClientIdentity, CommitCheckOptions, CommitFilesOptions, GitCommitResult, GitTransport, IssuedAgentCredential, PullRequestDetail, PullRequestOptions, PullRequestRecord, RepositoryAutomation, RepositoryFile, RepositoryRefs, ReviewOptions } from './types.js';
|
|
2
4
|
export declare class TraceGitError extends Error {
|
|
3
5
|
code: string;
|
|
4
6
|
status: number;
|
|
@@ -32,6 +34,7 @@ export interface RunOptions {
|
|
|
32
34
|
recordType?: 'connected' | 'validation';
|
|
33
35
|
externalSessionId?: string;
|
|
34
36
|
}
|
|
37
|
+
export type AgentRunOptions = Omit<RunOptions, 'projectId' | 'rootAgentId'>;
|
|
35
38
|
export interface GenerateOptions {
|
|
36
39
|
provider: Provider;
|
|
37
40
|
model: string;
|
|
@@ -64,7 +67,16 @@ export declare class TraceGitClient {
|
|
|
64
67
|
readonly url: string;
|
|
65
68
|
private readonly apiKey;
|
|
66
69
|
private readonly transport;
|
|
70
|
+
private authenticatedAgent?;
|
|
71
|
+
private pendingIdentity?;
|
|
67
72
|
constructor(options: ClientOptions);
|
|
73
|
+
get isAgentCredential(): boolean;
|
|
74
|
+
private rememberIdentity;
|
|
75
|
+
/** Resolves machine authority once; every Worker operation still rechecks live authority. */
|
|
76
|
+
assignedAgent(): Promise<AgentIdentity | undefined>;
|
|
77
|
+
assertExecutionAgent(agentId: string): Promise<void>;
|
|
78
|
+
private assertAdministration;
|
|
79
|
+
private authorizeProject;
|
|
68
80
|
raw(path: string, init?: RequestInit): Promise<Response>;
|
|
69
81
|
request<T>(path: string, method?: string, body?: unknown, idempotent?: boolean): Promise<T>;
|
|
70
82
|
createAgent(options: AgentOptions): Promise<{
|
|
@@ -72,26 +84,51 @@ export declare class TraceGitClient {
|
|
|
72
84
|
version: number;
|
|
73
85
|
}>;
|
|
74
86
|
createRun(options: RunOptions): Promise<TraceExecution>;
|
|
87
|
+
createAgentRun(options: AgentRunOptions): Promise<TraceExecution>;
|
|
75
88
|
execution(runId: string, agentId: string): TraceExecution;
|
|
76
89
|
events(events: TraceEvent[]): Promise<{
|
|
77
90
|
inserted: number;
|
|
78
91
|
duplicates: number;
|
|
79
92
|
}>;
|
|
80
|
-
me(): Promise<
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
me(): Promise<ClientIdentity>;
|
|
94
|
+
agentIdentity(): Promise<AgentSession>;
|
|
95
|
+
repositoryAutomation(projectId: string): Promise<RepositoryAutomation>;
|
|
96
|
+
configureAgentRepository(projectId: string, expectedVersion?: number): Promise<{
|
|
97
|
+
mode: "agents-only";
|
|
98
|
+
version: number;
|
|
99
|
+
}>;
|
|
100
|
+
listAgentAccess(projectId: string): Promise<AgentAccessRecord[]>;
|
|
101
|
+
grantAgentAccess(projectId: string, agentId: string, options: AgentAccessOptions): Promise<{
|
|
102
|
+
agentId: string;
|
|
103
|
+
projectId: string;
|
|
104
|
+
generation: number;
|
|
105
|
+
}>;
|
|
106
|
+
issueAgentCredential(projectId: string, agentId: string, name: string, expiresInHours?: number): Promise<IssuedAgentCredential>;
|
|
107
|
+
listAgentCredentials(projectId: string): Promise<AgentCredentialRecord[]>;
|
|
108
|
+
revokeAgentAccess(projectId: string, agentId: string): Promise<{
|
|
109
|
+
revoked: true;
|
|
110
|
+
}>;
|
|
111
|
+
revokeAgentCredential(projectId: string, credentialId: string): Promise<{
|
|
112
|
+
revoked: true;
|
|
89
113
|
}>;
|
|
90
114
|
providerHeaders(runId: string, agentId: string, requestId?: string): Record<string, string>;
|
|
91
|
-
gitTransport(projectId: string):
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
115
|
+
gitTransport(projectId: string): GitTransport;
|
|
116
|
+
repositoryRefs(projectId: string): Promise<RepositoryRefs>;
|
|
117
|
+
readRepositoryFile(projectId: string, path: string, ref?: string): Promise<RepositoryFile>;
|
|
118
|
+
compareRepository(projectId: string, base: string, head: string): Promise<Record<string, unknown>>;
|
|
119
|
+
createBranch(projectId: string, branch: string, from: string, operationId?: string): Promise<GitCommitResult>;
|
|
120
|
+
commitFiles(projectId: string, options: CommitFilesOptions): Promise<GitCommitResult>;
|
|
121
|
+
listPullRequests(projectId: string): Promise<PullRequestRecord[]>;
|
|
122
|
+
pullRequest(projectId: string, pullId: string): Promise<PullRequestDetail>;
|
|
123
|
+
openPullRequest(projectId: string, options: PullRequestOptions): Promise<PullRequestRecord>;
|
|
124
|
+
reviewPullRequest(projectId: string, pullId: string, options: ReviewOptions): Promise<{
|
|
125
|
+
id: string;
|
|
126
|
+
}>;
|
|
127
|
+
recordCommitCheck(projectId: string, options: CommitCheckOptions): Promise<{
|
|
128
|
+
recorded: true;
|
|
129
|
+
}>;
|
|
130
|
+
mergePullRequest(projectId: string, pullId: string, expectedVersion: number, operationId?: string): Promise<GitCommitResult>;
|
|
131
|
+
publishRun(runId: string): Promise<Record<string, unknown>>;
|
|
95
132
|
createWallet(options: {
|
|
96
133
|
id?: string;
|
|
97
134
|
commandId?: string;
|
package/types/sdk/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { TraceGitClient, TraceExecution, TraceGitError } from './client.js';
|
|
2
2
|
export { TraceGitClient as BranchoraClient, TraceExecution as BranchoraExecution, TraceGitError as BranchoraError, } from './client.js';
|
|
3
|
-
export type { ClientOptions, AgentOptions, RunOptions, GenerateOptions, DecisionOptions, } from './client.js';
|
|
3
|
+
export type { ClientOptions, AgentOptions, RunOptions, AgentRunOptions, GenerateOptions, DecisionOptions, } from './client.js';
|
|
4
|
+
export type { AgentAccessOptions, AgentAccessRecord, AgentCredentialRecord, AgentPrincipal, AgentSession, ClientIdentity, ClientPrincipal, CommitCheckOptions, CommitFilesOptions, GitCommitResult, GitFileChange, GitTransport, IssuedAgentCredential, PullRequestDetail, PullRequestOptions, PullRequestRecord, RepositoryAutomation, RepositoryFile, RepositoryRefs, ReviewOptions, } from './types.js';
|
|
5
|
+
export { AGENT_CAPABILITIES, matchesAgentBranch } from '../core/agent-identity.js';
|
|
6
|
+
export type { AgentCapability, AgentIdentity } from '../core/agent-identity.js';
|
|
4
7
|
export { buildSharedContext, estimatedTextTokens } from '../core/context.js';
|
|
5
8
|
export { calculateCost, usdToNanos, nanosToUsd } from '../core/money.js';
|
|
6
9
|
export { normalizeUsage } from '../core/usage.js';
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { AgentCapability, AgentIdentity } from '../core/agent-identity.js';
|
|
2
|
+
export interface ClientPrincipal {
|
|
3
|
+
id?: string;
|
|
4
|
+
workspaceId: string;
|
|
5
|
+
role: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
source?: 'api-key' | 'session' | 'access' | 'agent';
|
|
8
|
+
agent?: AgentIdentity;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentPrincipal extends ClientPrincipal {
|
|
11
|
+
id: string;
|
|
12
|
+
role: 'operator';
|
|
13
|
+
source: 'agent';
|
|
14
|
+
agent: AgentIdentity;
|
|
15
|
+
}
|
|
16
|
+
export interface ClientIdentity {
|
|
17
|
+
principal: ClientPrincipal;
|
|
18
|
+
workspace: {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface AgentSession {
|
|
24
|
+
principal: AgentPrincipal;
|
|
25
|
+
protocol: 'branchora.agents.v1';
|
|
26
|
+
gitRemote: string;
|
|
27
|
+
headless: true;
|
|
28
|
+
}
|
|
29
|
+
export interface RepositoryAutomation {
|
|
30
|
+
mode: 'legacy' | 'agents-only';
|
|
31
|
+
version: number;
|
|
32
|
+
configured_at?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface AgentAccessOptions {
|
|
35
|
+
capabilities: AgentCapability[];
|
|
36
|
+
writeBranches: string[];
|
|
37
|
+
expectedGeneration?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Administration lists retain the server's field names and never include credential tokens. */
|
|
40
|
+
export interface AgentAccessRecord {
|
|
41
|
+
agent_id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
capabilities_json: string;
|
|
44
|
+
write_branches_json: string;
|
|
45
|
+
generation: number;
|
|
46
|
+
revoked_at: string | null;
|
|
47
|
+
configured_at: string;
|
|
48
|
+
}
|
|
49
|
+
export interface AgentCredentialRecord {
|
|
50
|
+
id: string;
|
|
51
|
+
agent_id: string;
|
|
52
|
+
project_id: string;
|
|
53
|
+
prefix: string;
|
|
54
|
+
name: string;
|
|
55
|
+
created_at: string;
|
|
56
|
+
expires_at: string;
|
|
57
|
+
revoked_at: string | null;
|
|
58
|
+
}
|
|
59
|
+
export interface IssuedAgentCredential {
|
|
60
|
+
id: string;
|
|
61
|
+
token: string;
|
|
62
|
+
expiresAt: string;
|
|
63
|
+
agentId: string;
|
|
64
|
+
projectId: string;
|
|
65
|
+
}
|
|
66
|
+
export interface GitTransport {
|
|
67
|
+
remote: string;
|
|
68
|
+
headers: Record<string, string>;
|
|
69
|
+
}
|
|
70
|
+
export interface RepositoryRefs {
|
|
71
|
+
branches: Array<{
|
|
72
|
+
name: string;
|
|
73
|
+
sha: string | null;
|
|
74
|
+
ref?: string;
|
|
75
|
+
}>;
|
|
76
|
+
tags: Array<{
|
|
77
|
+
name: string;
|
|
78
|
+
sha: string;
|
|
79
|
+
ref?: string;
|
|
80
|
+
}>;
|
|
81
|
+
defaultBranch: string;
|
|
82
|
+
}
|
|
83
|
+
export interface RepositoryFile {
|
|
84
|
+
path: string;
|
|
85
|
+
content: string | null;
|
|
86
|
+
binary: boolean;
|
|
87
|
+
bytes: number;
|
|
88
|
+
contentType: string;
|
|
89
|
+
}
|
|
90
|
+
export interface GitFileChange {
|
|
91
|
+
path: string;
|
|
92
|
+
/** null deletes the file. Empty content writes an empty file. */
|
|
93
|
+
content: string | null;
|
|
94
|
+
mode?: '100644' | '100755';
|
|
95
|
+
}
|
|
96
|
+
export interface CommitFilesOptions {
|
|
97
|
+
operationId?: string;
|
|
98
|
+
branch: string;
|
|
99
|
+
expectedHead: string | null;
|
|
100
|
+
message: string;
|
|
101
|
+
files: GitFileChange[];
|
|
102
|
+
runId?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface GitCommitResult {
|
|
105
|
+
sha: string;
|
|
106
|
+
branch?: string;
|
|
107
|
+
treeHash?: string;
|
|
108
|
+
created?: boolean;
|
|
109
|
+
method?: 'fast-forward' | 'merge-commit';
|
|
110
|
+
duplicate?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface PullRequestOptions {
|
|
113
|
+
title: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
sourceBranch: string;
|
|
116
|
+
targetBranch: string;
|
|
117
|
+
draft?: boolean;
|
|
118
|
+
}
|
|
119
|
+
export interface PullRequestRecord {
|
|
120
|
+
id: string;
|
|
121
|
+
project_id: string;
|
|
122
|
+
number: number;
|
|
123
|
+
title: string;
|
|
124
|
+
description: string;
|
|
125
|
+
source_branch: string;
|
|
126
|
+
target_branch: string;
|
|
127
|
+
base_sha: string;
|
|
128
|
+
head_sha: string;
|
|
129
|
+
merge_sha?: string | null;
|
|
130
|
+
target_sha?: string;
|
|
131
|
+
status: 'open' | 'closed' | 'merged';
|
|
132
|
+
draft: number;
|
|
133
|
+
author_id: string;
|
|
134
|
+
author_name: string;
|
|
135
|
+
version: number;
|
|
136
|
+
created_at: string;
|
|
137
|
+
updated_at: string;
|
|
138
|
+
}
|
|
139
|
+
export interface PullRequestDetail {
|
|
140
|
+
pull: PullRequestRecord;
|
|
141
|
+
reviews: Record<string, unknown>[];
|
|
142
|
+
comments: Record<string, unknown>[];
|
|
143
|
+
readiness: Record<string, unknown>;
|
|
144
|
+
}
|
|
145
|
+
export interface ReviewOptions {
|
|
146
|
+
state: 'approved' | 'changes_requested' | 'commented';
|
|
147
|
+
headSha: string;
|
|
148
|
+
body?: string;
|
|
149
|
+
}
|
|
150
|
+
export interface CommitCheckOptions {
|
|
151
|
+
commitSha: string;
|
|
152
|
+
name: string;
|
|
153
|
+
status: 'pending' | 'passed' | 'failed';
|
|
154
|
+
details?: Record<string, unknown>;
|
|
155
|
+
}
|