@clinebot/shared 0.0.8 → 0.0.9
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/dist/index.browser.d.ts +25 -0
- package/dist/index.browser.js +49 -0
- package/package.json +10 -3
- package/src/auth/constants.ts +41 -0
- package/src/connectors/events.ts +29 -0
- package/src/db/index.ts +14 -0
- package/src/db/sqlite-db.ts +271 -0
- package/src/index.browser.ts +131 -0
- package/src/index.ts +131 -0
- package/src/llms/model-id.ts +154 -0
- package/src/llms/tools.ts +137 -0
- package/src/logging/logger.ts +9 -0
- package/src/parse/json.ts +43 -0
- package/src/parse/time.ts +21 -0
- package/src/parse/zod.ts +23 -0
- package/src/prompt/format.ts +22 -0
- package/src/rpc/runtime.ts +316 -0
- package/src/rpc/team-progress.ts +71 -0
- package/src/services/telemetry-config.ts +55 -0
- package/src/services/telemetry.ts +141 -0
- package/src/session/hook-context.ts +54 -0
- package/src/session/records.ts +40 -0
- package/src/session/runtime-config.ts +24 -0
- package/src/session/runtime-env.ts +8 -0
- package/src/storage/index.ts +29 -0
- package/src/storage/paths.ts +202 -0
- package/src/vcr.ts +717 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentMode,
|
|
3
|
+
SessionExecutionConfig,
|
|
4
|
+
SessionPromptConfig,
|
|
5
|
+
} from "../session/runtime-config";
|
|
6
|
+
|
|
7
|
+
export type RpcAgentMode = AgentMode;
|
|
8
|
+
|
|
9
|
+
export interface RpcSessionStorageOptions {
|
|
10
|
+
homeDir?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface RpcChatRuntimeConfigBase extends SessionPromptConfig {
|
|
14
|
+
cwd?: string;
|
|
15
|
+
apiKey: string;
|
|
16
|
+
logger?: RpcChatRuntimeLoggerConfig;
|
|
17
|
+
enableTools: boolean;
|
|
18
|
+
enableSpawn: boolean;
|
|
19
|
+
enableTeams: boolean;
|
|
20
|
+
autoApproveTools?: boolean;
|
|
21
|
+
teamName: string;
|
|
22
|
+
missionStepInterval: number;
|
|
23
|
+
missionTimeIntervalMs: number;
|
|
24
|
+
toolPolicies?: SessionExecutionConfig["toolPolicies"];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RpcChatRuntimeLoggerConfig {
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
level?: "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
|
|
30
|
+
destination?: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
bindings?: Record<string, string | number | boolean>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RpcChatStartSessionRequest extends RpcChatRuntimeConfigBase {
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
workspaceRoot: string;
|
|
38
|
+
provider: string;
|
|
39
|
+
model: string;
|
|
40
|
+
sessions?: RpcSessionStorageOptions;
|
|
41
|
+
initialMessages?: RpcChatMessage[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface RpcChatStartSessionArtifacts {
|
|
45
|
+
sessionId: string;
|
|
46
|
+
manifestPath: string;
|
|
47
|
+
transcriptPath: string;
|
|
48
|
+
hookPath: string;
|
|
49
|
+
messagesPath: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface RpcChatStartSessionResponse {
|
|
53
|
+
sessionId: string;
|
|
54
|
+
startResult?: RpcChatStartSessionArtifacts;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface RpcChatAttachmentFile {
|
|
58
|
+
name: string;
|
|
59
|
+
content: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface RpcChatAttachments {
|
|
63
|
+
userImages?: string[];
|
|
64
|
+
userFiles?: RpcChatAttachmentFile[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface RpcChatMessage {
|
|
68
|
+
role?: string;
|
|
69
|
+
content?: unknown;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface RpcChatRunTurnRequest {
|
|
74
|
+
config: RpcChatStartSessionRequest;
|
|
75
|
+
messages?: RpcChatMessage[];
|
|
76
|
+
prompt: string;
|
|
77
|
+
attachments?: RpcChatAttachments;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface RpcChatToolCallResult {
|
|
81
|
+
name: string;
|
|
82
|
+
input?: unknown;
|
|
83
|
+
output?: unknown;
|
|
84
|
+
error?: string;
|
|
85
|
+
durationMs?: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface RpcChatTurnResult {
|
|
89
|
+
text: string;
|
|
90
|
+
usage: {
|
|
91
|
+
inputTokens: number;
|
|
92
|
+
outputTokens: number;
|
|
93
|
+
cacheReadTokens?: number;
|
|
94
|
+
cacheWriteTokens?: number;
|
|
95
|
+
totalCost?: number;
|
|
96
|
+
};
|
|
97
|
+
inputTokens: number;
|
|
98
|
+
outputTokens: number;
|
|
99
|
+
iterations: number;
|
|
100
|
+
finishReason: string;
|
|
101
|
+
messages: RpcChatMessage[];
|
|
102
|
+
toolCalls: RpcChatToolCallResult[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface RpcProviderModel {
|
|
106
|
+
id: string;
|
|
107
|
+
name: string;
|
|
108
|
+
supportsAttachments?: boolean;
|
|
109
|
+
supportsVision?: boolean;
|
|
110
|
+
supportsReasoning?: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface RpcProviderListItem {
|
|
114
|
+
id: string;
|
|
115
|
+
name: string;
|
|
116
|
+
models: number | null;
|
|
117
|
+
color: string;
|
|
118
|
+
letter: string;
|
|
119
|
+
enabled: boolean;
|
|
120
|
+
apiKey?: string;
|
|
121
|
+
oauthAccessTokenPresent?: boolean;
|
|
122
|
+
baseUrl?: string;
|
|
123
|
+
defaultModelId?: string;
|
|
124
|
+
authDescription: string;
|
|
125
|
+
baseUrlDescription: string;
|
|
126
|
+
modelList?: RpcProviderModel[];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface RpcProviderCatalogResponse {
|
|
130
|
+
providers: RpcProviderListItem[];
|
|
131
|
+
settingsPath: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface RpcProviderModelsResponse {
|
|
135
|
+
providerId: string;
|
|
136
|
+
models: RpcProviderModel[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface RpcClineAccountOrganization {
|
|
140
|
+
active: boolean;
|
|
141
|
+
memberId: string;
|
|
142
|
+
name: string;
|
|
143
|
+
organizationId: string;
|
|
144
|
+
roles: Array<"admin" | "member" | "owner">;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface RpcClineAccountUser {
|
|
148
|
+
id: string;
|
|
149
|
+
email: string;
|
|
150
|
+
displayName: string;
|
|
151
|
+
photoUrl: string;
|
|
152
|
+
createdAt: string;
|
|
153
|
+
updatedAt: string;
|
|
154
|
+
organizations: RpcClineAccountOrganization[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface RpcClineAccountBalance {
|
|
158
|
+
balance: number;
|
|
159
|
+
userId: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface RpcClineAccountUsageTransaction {
|
|
163
|
+
aiInferenceProviderName: string;
|
|
164
|
+
aiModelName: string;
|
|
165
|
+
aiModelTypeName: string;
|
|
166
|
+
completionTokens: number;
|
|
167
|
+
costUsd: number;
|
|
168
|
+
createdAt: string;
|
|
169
|
+
creditsUsed: number;
|
|
170
|
+
generationId: string;
|
|
171
|
+
id: string;
|
|
172
|
+
metadata: {
|
|
173
|
+
additionalProp1: string;
|
|
174
|
+
additionalProp2: string;
|
|
175
|
+
additionalProp3: string;
|
|
176
|
+
};
|
|
177
|
+
operation?: string;
|
|
178
|
+
organizationId: string;
|
|
179
|
+
promptTokens: number;
|
|
180
|
+
totalTokens: number;
|
|
181
|
+
userId: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface RpcClineAccountPaymentTransaction {
|
|
185
|
+
paidAt: string;
|
|
186
|
+
creatorId: string;
|
|
187
|
+
amountCents: number;
|
|
188
|
+
credits: number;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface RpcClineAccountOrganizationBalance {
|
|
192
|
+
balance: number;
|
|
193
|
+
organizationId: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface RpcClineAccountOrganizationUsageTransaction {
|
|
197
|
+
aiInferenceProviderName: string;
|
|
198
|
+
aiModelName: string;
|
|
199
|
+
aiModelTypeName: string;
|
|
200
|
+
completionTokens: number;
|
|
201
|
+
costUsd: number;
|
|
202
|
+
createdAt: string;
|
|
203
|
+
creditsUsed: number;
|
|
204
|
+
generationId: string;
|
|
205
|
+
id: string;
|
|
206
|
+
memberDisplayName: string;
|
|
207
|
+
memberEmail: string;
|
|
208
|
+
metadata: {
|
|
209
|
+
additionalProp1: string;
|
|
210
|
+
additionalProp2: string;
|
|
211
|
+
additionalProp3: string;
|
|
212
|
+
};
|
|
213
|
+
operation?: string;
|
|
214
|
+
organizationId: string;
|
|
215
|
+
promptTokens: number;
|
|
216
|
+
totalTokens: number;
|
|
217
|
+
userId: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
import type { OAuthProviderId } from "../auth/constants";
|
|
221
|
+
|
|
222
|
+
export type RpcOAuthProviderId = OAuthProviderId;
|
|
223
|
+
|
|
224
|
+
export type RpcProviderCapability =
|
|
225
|
+
| "reasoning"
|
|
226
|
+
| "prompt-cache"
|
|
227
|
+
| "streaming"
|
|
228
|
+
| "tools"
|
|
229
|
+
| "vision";
|
|
230
|
+
|
|
231
|
+
export interface RpcListProvidersActionRequest {
|
|
232
|
+
action: "listProviders";
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface RpcGetProviderModelsActionRequest {
|
|
236
|
+
action: "getProviderModels";
|
|
237
|
+
providerId: string;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface RpcSaveProviderSettingsActionRequest {
|
|
241
|
+
action: "saveProviderSettings";
|
|
242
|
+
providerId: string;
|
|
243
|
+
enabled?: boolean;
|
|
244
|
+
apiKey?: string;
|
|
245
|
+
baseUrl?: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface RpcAddProviderActionRequest {
|
|
249
|
+
action: "addProvider";
|
|
250
|
+
providerId: string;
|
|
251
|
+
name: string;
|
|
252
|
+
baseUrl: string;
|
|
253
|
+
apiKey?: string;
|
|
254
|
+
headers?: Record<string, string>;
|
|
255
|
+
timeoutMs?: number;
|
|
256
|
+
models?: string[];
|
|
257
|
+
defaultModelId?: string;
|
|
258
|
+
modelsSourceUrl?: string;
|
|
259
|
+
capabilities?: RpcProviderCapability[];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export type RpcProviderSettingsActionRequest =
|
|
263
|
+
| RpcListProvidersActionRequest
|
|
264
|
+
| RpcGetProviderModelsActionRequest
|
|
265
|
+
| RpcSaveProviderSettingsActionRequest
|
|
266
|
+
| RpcAddProviderActionRequest;
|
|
267
|
+
|
|
268
|
+
export type RpcClineAccountActionRequest =
|
|
269
|
+
| {
|
|
270
|
+
action: "clineAccount";
|
|
271
|
+
operation: "fetchMe";
|
|
272
|
+
}
|
|
273
|
+
| {
|
|
274
|
+
action: "clineAccount";
|
|
275
|
+
operation: "fetchBalance";
|
|
276
|
+
userId?: string;
|
|
277
|
+
}
|
|
278
|
+
| {
|
|
279
|
+
action: "clineAccount";
|
|
280
|
+
operation: "fetchUsageTransactions";
|
|
281
|
+
userId?: string;
|
|
282
|
+
}
|
|
283
|
+
| {
|
|
284
|
+
action: "clineAccount";
|
|
285
|
+
operation: "fetchPaymentTransactions";
|
|
286
|
+
userId?: string;
|
|
287
|
+
}
|
|
288
|
+
| {
|
|
289
|
+
action: "clineAccount";
|
|
290
|
+
operation: "fetchUserOrganizations";
|
|
291
|
+
}
|
|
292
|
+
| {
|
|
293
|
+
action: "clineAccount";
|
|
294
|
+
operation: "fetchOrganizationBalance";
|
|
295
|
+
organizationId: string;
|
|
296
|
+
}
|
|
297
|
+
| {
|
|
298
|
+
action: "clineAccount";
|
|
299
|
+
operation: "fetchOrganizationUsageTransactions";
|
|
300
|
+
organizationId: string;
|
|
301
|
+
memberId?: string;
|
|
302
|
+
}
|
|
303
|
+
| {
|
|
304
|
+
action: "clineAccount";
|
|
305
|
+
operation: "switchAccount";
|
|
306
|
+
organizationId?: string | null;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export type RpcProviderActionRequest =
|
|
310
|
+
| RpcProviderSettingsActionRequest
|
|
311
|
+
| RpcClineAccountActionRequest;
|
|
312
|
+
|
|
313
|
+
export interface RpcProviderOAuthLoginResponse {
|
|
314
|
+
provider: RpcOAuthProviderId;
|
|
315
|
+
accessToken: string;
|
|
316
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const RPC_TEAM_PROGRESS_EVENT_TYPE = "runtime.team.progress.v1";
|
|
2
|
+
export const RPC_TEAM_LIFECYCLE_EVENT_TYPE = "runtime.team.lifecycle.v1";
|
|
3
|
+
|
|
4
|
+
export type TeamProgressMemberRole = "lead" | "teammate";
|
|
5
|
+
export type TeamProgressMemberStatus = "idle" | "running" | "stopped";
|
|
6
|
+
export type TeamProgressTaskStatus =
|
|
7
|
+
| "pending"
|
|
8
|
+
| "in_progress"
|
|
9
|
+
| "blocked"
|
|
10
|
+
| "completed";
|
|
11
|
+
export type TeamProgressRunStatus =
|
|
12
|
+
| "queued"
|
|
13
|
+
| "running"
|
|
14
|
+
| "completed"
|
|
15
|
+
| "failed"
|
|
16
|
+
| "cancelled"
|
|
17
|
+
| "interrupted";
|
|
18
|
+
export type TeamProgressOutcomeStatus = "draft" | "in_review" | "finalized";
|
|
19
|
+
export type TeamProgressOutcomeFragmentStatus =
|
|
20
|
+
| "draft"
|
|
21
|
+
| "reviewed"
|
|
22
|
+
| "rejected";
|
|
23
|
+
|
|
24
|
+
export interface TeamProgressCounts<TStatus extends string> {
|
|
25
|
+
total: number;
|
|
26
|
+
byStatus: Record<TStatus, number>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface TeamProgressSummary {
|
|
30
|
+
teamName: string;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
members: TeamProgressCounts<TeamProgressMemberStatus> & {
|
|
33
|
+
leadCount: number;
|
|
34
|
+
teammateCount: number;
|
|
35
|
+
};
|
|
36
|
+
tasks: TeamProgressCounts<TeamProgressTaskStatus> & {
|
|
37
|
+
blockedTaskIds: string[];
|
|
38
|
+
readyTaskIds: string[];
|
|
39
|
+
completionPct: number;
|
|
40
|
+
};
|
|
41
|
+
runs: TeamProgressCounts<TeamProgressRunStatus> & {
|
|
42
|
+
activeRunIds: string[];
|
|
43
|
+
latestRunId?: string;
|
|
44
|
+
};
|
|
45
|
+
outcomes: TeamProgressCounts<TeamProgressOutcomeStatus> & {
|
|
46
|
+
finalizedPct: number;
|
|
47
|
+
missingRequiredSections: string[];
|
|
48
|
+
};
|
|
49
|
+
fragments: TeamProgressCounts<TeamProgressOutcomeFragmentStatus>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface TeamProgressLifecycleEvent {
|
|
53
|
+
teamName: string;
|
|
54
|
+
sessionId: string;
|
|
55
|
+
eventType: string;
|
|
56
|
+
ts: string;
|
|
57
|
+
agentId?: string;
|
|
58
|
+
taskId?: string;
|
|
59
|
+
runId?: string;
|
|
60
|
+
outcomeId?: string;
|
|
61
|
+
fragmentId?: string;
|
|
62
|
+
message?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface TeamProgressProjectionEvent {
|
|
66
|
+
type: "team_progress_projection";
|
|
67
|
+
version: 1;
|
|
68
|
+
sessionId: string;
|
|
69
|
+
summary: TeamProgressSummary;
|
|
70
|
+
lastEvent: TeamProgressLifecycleEvent;
|
|
71
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { OpenTelemetryClientConfig, TelemetryMetadata } from "./telemetry";
|
|
2
|
+
|
|
3
|
+
export interface ClineTelemetryServiceConfig extends OpenTelemetryClientConfig {
|
|
4
|
+
metadata: TelemetryMetadata;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function getTelemetryBuildTimeConfig(): OpenTelemetryClientConfig {
|
|
8
|
+
return {
|
|
9
|
+
enabled:
|
|
10
|
+
process?.env?.OTEL_TELEMETRY_ENABLED === "1" ||
|
|
11
|
+
process?.env?.OTEL_TELEMETRY_ENABLED === "true",
|
|
12
|
+
metricsExporter: process?.env?.OTEL_METRICS_EXPORTER || "otlp",
|
|
13
|
+
logsExporter: process?.env?.OTEL_LOGS_EXPORTER || "otlp",
|
|
14
|
+
otlpProtocol: process?.env?.OTEL_EXPORTER_OTLP_PROTOCOL || "http/json",
|
|
15
|
+
otlpEndpoint: process?.env?.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
16
|
+
metricExportInterval: process?.env?.OTEL_METRIC_EXPORT_INTERVAL
|
|
17
|
+
? Number.parseInt(process?.env?.OTEL_METRIC_EXPORT_INTERVAL, 10)
|
|
18
|
+
: undefined,
|
|
19
|
+
otlpHeaders: process?.env?.OTEL_EXPORTER_OTLP_HEADERS
|
|
20
|
+
? Object.fromEntries(
|
|
21
|
+
process?.env?.OTEL_EXPORTER_OTLP_HEADERS.split(",").map((header) => {
|
|
22
|
+
const [key, value] = header.split("=");
|
|
23
|
+
return [key.trim(), value.trim()];
|
|
24
|
+
}),
|
|
25
|
+
)
|
|
26
|
+
: undefined,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createClineTelemetryServiceMetadata(
|
|
31
|
+
overrides: Partial<TelemetryMetadata> = {},
|
|
32
|
+
): TelemetryMetadata {
|
|
33
|
+
return {
|
|
34
|
+
extension_version: "unknown",
|
|
35
|
+
cline_type: "unknown",
|
|
36
|
+
platform: "terminal",
|
|
37
|
+
platform_version: process?.version || "unknown",
|
|
38
|
+
os_type: process?.platform || "unknown",
|
|
39
|
+
os_version:
|
|
40
|
+
process?.platform === "win32"
|
|
41
|
+
? (process?.env?.OS ?? "unknown")
|
|
42
|
+
: "unknown",
|
|
43
|
+
...overrides,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createClineTelemetryServiceConfig(
|
|
48
|
+
configOverrides: Partial<ClineTelemetryServiceConfig> = {},
|
|
49
|
+
): ClineTelemetryServiceConfig {
|
|
50
|
+
return {
|
|
51
|
+
...getTelemetryBuildTimeConfig(),
|
|
52
|
+
...configOverrides,
|
|
53
|
+
metadata: createClineTelemetryServiceMetadata(configOverrides.metadata),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export type TelemetryPrimitive = string | number | boolean | null | undefined;
|
|
2
|
+
|
|
3
|
+
export type TelemetryValue =
|
|
4
|
+
| TelemetryPrimitive
|
|
5
|
+
| TelemetryObject
|
|
6
|
+
| TelemetryArray;
|
|
7
|
+
|
|
8
|
+
export type TelemetryObject = { [key: string]: TelemetryValue };
|
|
9
|
+
|
|
10
|
+
export type TelemetryArray = Array<TelemetryValue>;
|
|
11
|
+
|
|
12
|
+
export type TelemetryProperties = TelemetryObject;
|
|
13
|
+
|
|
14
|
+
export interface TelemetryMetadata {
|
|
15
|
+
extension_version: string;
|
|
16
|
+
cline_type: string;
|
|
17
|
+
platform: string;
|
|
18
|
+
platform_version: string;
|
|
19
|
+
os_type: string;
|
|
20
|
+
os_version: string;
|
|
21
|
+
is_dev?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ITelemetryService {
|
|
25
|
+
setDistinctId(distinctId?: string): void;
|
|
26
|
+
setMetadata(metadata: Partial<TelemetryMetadata>): void;
|
|
27
|
+
updateMetadata(metadata: Partial<TelemetryMetadata>): void;
|
|
28
|
+
setCommonProperties(properties: TelemetryProperties): void;
|
|
29
|
+
updateCommonProperties(properties: TelemetryProperties): void;
|
|
30
|
+
isEnabled(): boolean;
|
|
31
|
+
capture(input: { event: string; properties?: TelemetryProperties }): void;
|
|
32
|
+
captureRequired(event: string, properties?: TelemetryProperties): void;
|
|
33
|
+
recordCounter(
|
|
34
|
+
name: string,
|
|
35
|
+
value: number,
|
|
36
|
+
attributes?: TelemetryProperties,
|
|
37
|
+
description?: string,
|
|
38
|
+
required?: boolean,
|
|
39
|
+
): void;
|
|
40
|
+
recordHistogram(
|
|
41
|
+
name: string,
|
|
42
|
+
value: number,
|
|
43
|
+
attributes?: TelemetryProperties,
|
|
44
|
+
description?: string,
|
|
45
|
+
required?: boolean,
|
|
46
|
+
): void;
|
|
47
|
+
recordGauge(
|
|
48
|
+
name: string,
|
|
49
|
+
value: number | null,
|
|
50
|
+
attributes?: TelemetryProperties,
|
|
51
|
+
description?: string,
|
|
52
|
+
required?: boolean,
|
|
53
|
+
): void;
|
|
54
|
+
flush(): Promise<void>;
|
|
55
|
+
dispose(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface OpenTelemetryClientConfig {
|
|
59
|
+
/**
|
|
60
|
+
* Whether telemetry is enabled via OTEL_TELEMETRY_ENABLED
|
|
61
|
+
*/
|
|
62
|
+
enabled: boolean;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Metrics exporter type(s) - can be comma-separated for multiple exporters
|
|
66
|
+
* Examples: "console", "otlp", "prometheus", "console,otlp"
|
|
67
|
+
*/
|
|
68
|
+
metricsExporter?: string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Logs/events exporter type(s) - can be comma-separated for multiple exporters
|
|
72
|
+
* Examples: "console", "otlp"
|
|
73
|
+
*/
|
|
74
|
+
logsExporter?: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Protocol for OTLP exporters. SDK support is currently limited to "http/json".
|
|
78
|
+
*/
|
|
79
|
+
otlpProtocol?: string;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* General OTLP endpoint (used if specific endpoints not set)
|
|
83
|
+
*/
|
|
84
|
+
otlpEndpoint?: string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* General OTLP headers
|
|
88
|
+
*/
|
|
89
|
+
otlpHeaders?: Record<string, string>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Metrics-specific OTLP protocol
|
|
93
|
+
*/
|
|
94
|
+
otlpMetricsProtocol?: string;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Metrics-specific OTLP endpoint
|
|
98
|
+
*/
|
|
99
|
+
otlpMetricsEndpoint?: string;
|
|
100
|
+
|
|
101
|
+
otlpMetricsHeaders?: Record<string, string>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Logs-specific OTLP protocol
|
|
105
|
+
*/
|
|
106
|
+
otlpLogsProtocol?: string;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Logs-specific OTLP endpoint
|
|
110
|
+
*/
|
|
111
|
+
otlpLogsEndpoint?: string;
|
|
112
|
+
|
|
113
|
+
otlpLogsHeaders?: Record<string, string>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Metric export interval in milliseconds (for console exporter)
|
|
117
|
+
*/
|
|
118
|
+
metricExportInterval?: number;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether to use insecure (non-TLS) connections for gRPC OTLP exporters
|
|
122
|
+
* Set to "true" for local development without TLS
|
|
123
|
+
* Default: false (uses TLS)
|
|
124
|
+
*/
|
|
125
|
+
otlpInsecure?: boolean;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Maximum batch size for log records (default: 512)
|
|
129
|
+
*/
|
|
130
|
+
logBatchSize?: number;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Maximum time to wait before exporting logs in milliseconds (default: 5000)
|
|
134
|
+
*/
|
|
135
|
+
logBatchTimeout?: number;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Maximum queue size for log records (default: 2048)
|
|
139
|
+
*/
|
|
140
|
+
logMaxQueueSize?: number;
|
|
141
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface HookSessionContext {
|
|
2
|
+
rootSessionId?: string;
|
|
3
|
+
hookLogPath?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface HookSessionContextLookup {
|
|
7
|
+
hookName?: string;
|
|
8
|
+
conversationId?: string;
|
|
9
|
+
agentId?: string;
|
|
10
|
+
parentAgentId?: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type HookSessionContextProvider =
|
|
14
|
+
| HookSessionContext
|
|
15
|
+
| ((input?: HookSessionContextLookup) => HookSessionContext | undefined);
|
|
16
|
+
|
|
17
|
+
function normalized(value: string | undefined): string | undefined {
|
|
18
|
+
const trimmed = value?.trim();
|
|
19
|
+
return trimmed ? trimmed : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function resolveHookSessionContext(
|
|
23
|
+
provider?: HookSessionContextProvider,
|
|
24
|
+
input?: HookSessionContextLookup,
|
|
25
|
+
): HookSessionContext | undefined {
|
|
26
|
+
if (!provider) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const context = typeof provider === "function" ? provider(input) : provider;
|
|
30
|
+
if (!context) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const rootSessionId = normalized(context.rootSessionId);
|
|
34
|
+
const hookLogPath = normalized(context.hookLogPath);
|
|
35
|
+
if (!rootSessionId && !hookLogPath) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
rootSessionId,
|
|
40
|
+
hookLogPath,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function resolveRootSessionId(
|
|
45
|
+
context: HookSessionContext | undefined,
|
|
46
|
+
): string | undefined {
|
|
47
|
+
return normalized(context?.rootSessionId);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function resolveHookLogPath(
|
|
51
|
+
context: HookSessionContext | undefined,
|
|
52
|
+
): string | undefined {
|
|
53
|
+
return normalized(context?.hookLogPath);
|
|
54
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const SESSION_STATUS_VALUES = [
|
|
2
|
+
"running",
|
|
3
|
+
"completed",
|
|
4
|
+
"failed",
|
|
5
|
+
"cancelled",
|
|
6
|
+
] as const;
|
|
7
|
+
|
|
8
|
+
export type SharedSessionStatus = (typeof SESSION_STATUS_VALUES)[number];
|
|
9
|
+
|
|
10
|
+
export interface SessionLineage {
|
|
11
|
+
parentSessionId?: string;
|
|
12
|
+
agentId?: string;
|
|
13
|
+
parentAgentId?: string;
|
|
14
|
+
conversationId?: string;
|
|
15
|
+
isSubagent: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SessionRuntimeRecordShape extends SessionLineage {
|
|
19
|
+
source: string;
|
|
20
|
+
pid?: number;
|
|
21
|
+
startedAt: string;
|
|
22
|
+
endedAt?: string | null;
|
|
23
|
+
exitCode?: number | null;
|
|
24
|
+
status: SharedSessionStatus;
|
|
25
|
+
interactive: boolean;
|
|
26
|
+
provider: string;
|
|
27
|
+
model: string;
|
|
28
|
+
cwd: string;
|
|
29
|
+
workspaceRoot: string;
|
|
30
|
+
teamName?: string;
|
|
31
|
+
enableTools: boolean;
|
|
32
|
+
enableSpawn: boolean;
|
|
33
|
+
enableTeams: boolean;
|
|
34
|
+
prompt?: string;
|
|
35
|
+
metadata?: Record<string, unknown>;
|
|
36
|
+
transcriptPath?: string;
|
|
37
|
+
hookPath?: string;
|
|
38
|
+
messagesPath?: string;
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ToolPolicy } from "../llms/tools";
|
|
2
|
+
|
|
3
|
+
export type AgentMode = "act" | "plan";
|
|
4
|
+
|
|
5
|
+
export interface SessionPromptConfig {
|
|
6
|
+
mode?: AgentMode;
|
|
7
|
+
systemPrompt?: string;
|
|
8
|
+
rules?: string;
|
|
9
|
+
maxIterations?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SessionWorkspaceConfig {
|
|
13
|
+
cwd: string;
|
|
14
|
+
workspaceRoot?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface SessionExecutionConfig {
|
|
18
|
+
enableTools: boolean;
|
|
19
|
+
teamName?: string;
|
|
20
|
+
missionLogIntervalSteps?: number;
|
|
21
|
+
missionLogIntervalMs?: number;
|
|
22
|
+
maxConsecutiveMistakes?: number;
|
|
23
|
+
toolPolicies?: Record<string, ToolPolicy>;
|
|
24
|
+
}
|