@locusai/shared 0.11.5 → 0.11.7
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/__tests__/protocol-contracts.test.d.ts +2 -0
- package/dist/__tests__/protocol-contracts.test.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +601 -0
- package/dist/protocol/cli-stream.d.ts +270 -0
- package/dist/protocol/cli-stream.d.ts.map +1 -0
- package/dist/protocol/context.d.ts +55 -0
- package/dist/protocol/context.d.ts.map +1 -0
- package/dist/protocol/envelope.d.ts +14 -0
- package/dist/protocol/envelope.d.ts.map +1 -0
- package/dist/protocol/errors.d.ts +44 -0
- package/dist/protocol/errors.d.ts.map +1 -0
- package/dist/protocol/helpers.d.ts +58 -0
- package/dist/protocol/helpers.d.ts.map +1 -0
- package/dist/protocol/host-events.d.ts +354 -0
- package/dist/protocol/host-events.d.ts.map +1 -0
- package/dist/protocol/index.d.ts +9 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/session.d.ts +97 -0
- package/dist/protocol/session.d.ts.map +1 -0
- package/dist/protocol/ui-intents.d.ts +165 -0
- package/dist/protocol/ui-intents.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-contracts.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/protocol-contracts.test.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -29,10 +29,23 @@ var __export = (target, all) => {
|
|
|
29
29
|
// src/index.ts
|
|
30
30
|
var exports_src = {};
|
|
31
31
|
__export(exports_src, {
|
|
32
|
+
parseUIIntent: () => parseUIIntent,
|
|
33
|
+
parseHostEvent: () => parseHostEvent,
|
|
34
|
+
parseCliStreamEvent: () => parseCliStreamEvent,
|
|
35
|
+
isValidTransition: () => isValidTransition,
|
|
36
|
+
isUIIntentType: () => isUIIntentType,
|
|
37
|
+
isTerminalStatus: () => isTerminalStatus,
|
|
32
38
|
isJwtUser: () => isJwtUser,
|
|
39
|
+
isHostEventType: () => isHostEventType,
|
|
33
40
|
isApiKeyUser: () => isApiKeyUser,
|
|
41
|
+
getNextStatus: () => getNextStatus,
|
|
34
42
|
getAuthUserId: () => getAuthUserId,
|
|
35
43
|
generateUUID: () => generateUUID,
|
|
44
|
+
createUIIntent: () => createUIIntent,
|
|
45
|
+
createProtocolError: () => createProtocolError,
|
|
46
|
+
createHostEvent: () => createHostEvent,
|
|
47
|
+
createErrorEvent: () => createErrorEvent,
|
|
48
|
+
createCliStreamEvent: () => createCliStreamEvent,
|
|
36
49
|
WorkspacesResponseSchema: () => WorkspacesResponseSchema,
|
|
37
50
|
WorkspaceStatsSchema: () => WorkspaceStatsSchema,
|
|
38
51
|
WorkspaceStatsResponseSchema: () => WorkspaceStatsResponseSchema,
|
|
@@ -40,7 +53,9 @@ __export(exports_src, {
|
|
|
40
53
|
WorkspaceResponseSchema: () => WorkspaceResponseSchema,
|
|
41
54
|
WorkspaceIdParamSchema: () => WorkspaceIdParamSchema,
|
|
42
55
|
WorkspaceCreatedPayloadSchema: () => WorkspaceCreatedPayloadSchema,
|
|
56
|
+
WorkspaceContextSchema: () => WorkspaceContextSchema,
|
|
43
57
|
WorkspaceAndUserParamSchema: () => WorkspaceAndUserParamSchema,
|
|
58
|
+
WebviewReadyIntentSchema: () => WebviewReadyIntentSchema,
|
|
44
59
|
VerifyOtpSchema: () => VerifyOtpSchema,
|
|
45
60
|
UserSchema: () => UserSchema,
|
|
46
61
|
UserRole: () => UserRole,
|
|
@@ -52,6 +67,16 @@ __export(exports_src, {
|
|
|
52
67
|
UpdateDocSchema: () => UpdateDocSchema,
|
|
53
68
|
UpdateDocGroupSchema: () => UpdateDocGroupSchema,
|
|
54
69
|
UnlockSchema: () => UnlockSchema,
|
|
70
|
+
UIIntentTypeSchema: () => UIIntentTypeSchema,
|
|
71
|
+
UIIntentType: () => UIIntentType,
|
|
72
|
+
UIIntentSchema: () => UIIntentSchema,
|
|
73
|
+
ToolStartedEventSchema: () => ToolStartedEventSchema,
|
|
74
|
+
ToolCompletedEventSchema: () => ToolCompletedEventSchema,
|
|
75
|
+
TimelineEntrySchema: () => TimelineEntrySchema,
|
|
76
|
+
TimelineEntryKindSchema: () => TimelineEntryKindSchema,
|
|
77
|
+
TimelineEntryKind: () => TimelineEntryKind,
|
|
78
|
+
ThinkingEventSchema: () => ThinkingEventSchema,
|
|
79
|
+
TextDeltaEventSchema: () => TextDeltaEventSchema,
|
|
55
80
|
TasksResponseSchema: () => TasksResponseSchema,
|
|
56
81
|
TaskStatus: () => TaskStatus,
|
|
57
82
|
TaskSchema: () => TaskSchema,
|
|
@@ -62,7 +87,10 @@ __export(exports_src, {
|
|
|
62
87
|
TaskIdOnlyParamSchema: () => TaskIdOnlyParamSchema,
|
|
63
88
|
TaskDeletedPayloadSchema: () => TaskDeletedPayloadSchema,
|
|
64
89
|
TaskCreatedPayloadSchema: () => TaskCreatedPayloadSchema,
|
|
90
|
+
TERMINAL_STATUSES: () => TERMINAL_STATUSES,
|
|
65
91
|
SuccessResponseSchema: () => SuccessResponseSchema,
|
|
92
|
+
SubmitPromptIntentSchema: () => SubmitPromptIntentSchema,
|
|
93
|
+
StopSessionIntentSchema: () => StopSessionIntentSchema,
|
|
66
94
|
StatusChangedPayloadSchema: () => StatusChangedPayloadSchema,
|
|
67
95
|
SprintsResponseSchema: () => SprintsResponseSchema,
|
|
68
96
|
SprintStatusChangedPayloadSchema: () => SprintStatusChangedPayloadSchema,
|
|
@@ -72,11 +100,31 @@ __export(exports_src, {
|
|
|
72
100
|
SprintQuerySchema: () => SprintQuerySchema,
|
|
73
101
|
SprintIdParamSchema: () => SprintIdParamSchema,
|
|
74
102
|
SprintCreatedPayloadSchema: () => SprintCreatedPayloadSchema,
|
|
103
|
+
SessionTransitionEventSchema: () => SessionTransitionEventSchema,
|
|
104
|
+
SessionTransitionEvent: () => SessionTransitionEvent,
|
|
105
|
+
SessionSummarySchema: () => SessionSummarySchema,
|
|
106
|
+
SessionStatusSchema: () => SessionStatusSchema,
|
|
107
|
+
SessionStatus: () => SessionStatus,
|
|
108
|
+
SessionStateEventSchema: () => SessionStateEventSchema,
|
|
109
|
+
SessionMetadataSchema: () => SessionMetadataSchema,
|
|
110
|
+
SessionListEventSchema: () => SessionListEventSchema,
|
|
111
|
+
SessionCompletedEventSchema: () => SessionCompletedEventSchema,
|
|
112
|
+
SelectionContextSchema: () => SelectionContextSchema,
|
|
75
113
|
STALE_AGENT_TIMEOUT_MS: () => STALE_AGENT_TIMEOUT_MS,
|
|
114
|
+
SESSION_TRANSITIONS: () => SESSION_TRANSITIONS,
|
|
115
|
+
ResumeSessionIntentSchema: () => ResumeSessionIntentSchema,
|
|
116
|
+
RequestSessionsIntentSchema: () => RequestSessionsIntentSchema,
|
|
117
|
+
RequestSessionDetailIntentSchema: () => RequestSessionDetailIntentSchema,
|
|
76
118
|
ReportCiResultSchema: () => ReportCiResultSchema,
|
|
77
119
|
RecordCiSchema: () => RecordCiSchema,
|
|
120
|
+
ProtocolVersionSchema: () => ProtocolVersionSchema,
|
|
121
|
+
ProtocolErrorSchema: () => ProtocolErrorSchema,
|
|
122
|
+
ProtocolErrorCodeSchema: () => ProtocolErrorCodeSchema,
|
|
123
|
+
ProtocolErrorCode: () => ProtocolErrorCode,
|
|
124
|
+
ProtocolEnvelopeSchema: () => ProtocolEnvelopeSchema,
|
|
78
125
|
PaginationRequestSchema: () => PaginationRequestSchema,
|
|
79
126
|
PaginationMetaSchema: () => PaginationMetaSchema,
|
|
127
|
+
PROTOCOL_VERSION: () => PROTOCOL_VERSION,
|
|
80
128
|
OtpRequestSchema: () => OtpRequestSchema,
|
|
81
129
|
OrganizationsResponseSchema: () => OrganizationsResponseSchema,
|
|
82
130
|
OrganizationSchema: () => OrganizationSchema,
|
|
@@ -98,6 +146,9 @@ __export(exports_src, {
|
|
|
98
146
|
InvitationResponseSchema: () => InvitationResponseSchema,
|
|
99
147
|
InvitationQuerySchema: () => InvitationQuerySchema,
|
|
100
148
|
InvitationIdParamSchema: () => InvitationIdParamSchema,
|
|
149
|
+
HostEventTypeSchema: () => HostEventTypeSchema,
|
|
150
|
+
HostEventType: () => HostEventType,
|
|
151
|
+
HostEventSchema: () => HostEventSchema,
|
|
101
152
|
EventsResponseSchema: () => EventsResponseSchema,
|
|
102
153
|
EventType: () => EventType,
|
|
103
154
|
EventSchema: () => EventSchema,
|
|
@@ -105,6 +156,7 @@ __export(exports_src, {
|
|
|
105
156
|
EventQuerySchema: () => EventQuerySchema,
|
|
106
157
|
EventPayloadSchema: () => EventPayloadSchema,
|
|
107
158
|
ErrorResponseSchema: () => ErrorResponseSchema,
|
|
159
|
+
ErrorEventSchema: () => ErrorEventSchema,
|
|
108
160
|
DocsResponseSchema: () => DocsResponseSchema,
|
|
109
161
|
DocType: () => DocType,
|
|
110
162
|
DocSchema: () => DocSchema,
|
|
@@ -127,10 +179,23 @@ __export(exports_src, {
|
|
|
127
179
|
CreateDocGroupSchema: () => CreateDocGroupSchema,
|
|
128
180
|
CreateArtifactSchema: () => CreateArtifactSchema,
|
|
129
181
|
CreateApiKeySchema: () => CreateApiKeySchema,
|
|
182
|
+
ContextPayloadSchema: () => ContextPayloadSchema,
|
|
130
183
|
CompleteRegistrationSchema: () => CompleteRegistrationSchema,
|
|
131
184
|
CommentSchema: () => CommentSchema,
|
|
132
185
|
CommentResponseSchema: () => CommentResponseSchema,
|
|
133
186
|
CommentAddedPayloadSchema: () => CommentAddedPayloadSchema,
|
|
187
|
+
CliToolStartedEventSchema: () => CliToolStartedEventSchema,
|
|
188
|
+
CliToolCompletedEventSchema: () => CliToolCompletedEventSchema,
|
|
189
|
+
CliThinkingEventSchema: () => CliThinkingEventSchema,
|
|
190
|
+
CliTextDeltaEventSchema: () => CliTextDeltaEventSchema,
|
|
191
|
+
CliStreamEventTypeSchema: () => CliStreamEventTypeSchema,
|
|
192
|
+
CliStreamEventType: () => CliStreamEventType,
|
|
193
|
+
CliStreamEventSchema: () => CliStreamEventSchema,
|
|
194
|
+
CliStatusEventSchema: () => CliStatusEventSchema,
|
|
195
|
+
CliStartEventSchema: () => CliStartEventSchema,
|
|
196
|
+
CliErrorEventSchema: () => CliErrorEventSchema,
|
|
197
|
+
CliDoneEventSchema: () => CliDoneEventSchema,
|
|
198
|
+
ClearSessionIntentSchema: () => ClearSessionIntentSchema,
|
|
134
199
|
CiRanPayloadSchema: () => CiRanPayloadSchema,
|
|
135
200
|
ChecklistItemSchema: () => ChecklistItemSchema,
|
|
136
201
|
ChecklistInitializedPayloadSchema: () => ChecklistInitializedPayloadSchema,
|
|
@@ -154,6 +219,7 @@ __export(exports_src, {
|
|
|
154
219
|
AddMemberSchema: () => AddMemberSchema,
|
|
155
220
|
AddCommentSchema: () => AddCommentSchema,
|
|
156
221
|
ActivityResponseSchema: () => ActivityResponseSchema,
|
|
222
|
+
ActiveFileContextSchema: () => ActiveFileContextSchema,
|
|
157
223
|
AcceptanceItemSchema: () => AcceptanceItemSchema,
|
|
158
224
|
AcceptInvitationSchema: () => AcceptInvitationSchema,
|
|
159
225
|
AcceptInvitationResponseSchema: () => AcceptInvitationResponseSchema,
|
|
@@ -932,3 +998,538 @@ var WorkspaceStatsSchema = import_zod13.z.object({
|
|
|
932
998
|
var WorkspaceStatsResponseSchema = import_zod13.z.object({
|
|
933
999
|
stats: WorkspaceStatsSchema
|
|
934
1000
|
});
|
|
1001
|
+
// src/protocol/cli-stream.ts
|
|
1002
|
+
var import_zod16 = require("zod");
|
|
1003
|
+
|
|
1004
|
+
// src/protocol/envelope.ts
|
|
1005
|
+
var import_zod14 = require("zod");
|
|
1006
|
+
var PROTOCOL_VERSION = 1;
|
|
1007
|
+
var ProtocolVersionSchema = import_zod14.z.literal(PROTOCOL_VERSION);
|
|
1008
|
+
var ProtocolEnvelopeSchema = import_zod14.z.object({
|
|
1009
|
+
protocol: ProtocolVersionSchema,
|
|
1010
|
+
type: import_zod14.z.string()
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
// src/protocol/errors.ts
|
|
1014
|
+
var import_zod15 = require("zod");
|
|
1015
|
+
var ProtocolErrorCode = {
|
|
1016
|
+
CLI_NOT_FOUND: "CLI_NOT_FOUND",
|
|
1017
|
+
AUTH_EXPIRED: "AUTH_EXPIRED",
|
|
1018
|
+
NETWORK_TIMEOUT: "NETWORK_TIMEOUT",
|
|
1019
|
+
CONTEXT_LIMIT: "CONTEXT_LIMIT",
|
|
1020
|
+
MALFORMED_EVENT: "MALFORMED_EVENT",
|
|
1021
|
+
PROCESS_CRASHED: "PROCESS_CRASHED",
|
|
1022
|
+
SESSION_NOT_FOUND: "SESSION_NOT_FOUND",
|
|
1023
|
+
UNKNOWN: "UNKNOWN"
|
|
1024
|
+
};
|
|
1025
|
+
var ProtocolErrorCodeSchema = import_zod15.z.enum(ProtocolErrorCode);
|
|
1026
|
+
var ProtocolErrorSchema = import_zod15.z.object({
|
|
1027
|
+
code: ProtocolErrorCodeSchema,
|
|
1028
|
+
message: import_zod15.z.string(),
|
|
1029
|
+
details: import_zod15.z.unknown().optional(),
|
|
1030
|
+
recoverable: import_zod15.z.boolean()
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
// src/protocol/cli-stream.ts
|
|
1034
|
+
var CliStreamEventType = {
|
|
1035
|
+
START: "start",
|
|
1036
|
+
TEXT_DELTA: "text_delta",
|
|
1037
|
+
THINKING: "thinking",
|
|
1038
|
+
TOOL_STARTED: "tool_started",
|
|
1039
|
+
TOOL_COMPLETED: "tool_completed",
|
|
1040
|
+
STATUS: "status",
|
|
1041
|
+
ERROR: "error",
|
|
1042
|
+
DONE: "done"
|
|
1043
|
+
};
|
|
1044
|
+
var CliStreamEventTypeSchema = import_zod16.z.enum(CliStreamEventType);
|
|
1045
|
+
var CliStreamBaseSchema = import_zod16.z.object({
|
|
1046
|
+
protocol: ProtocolVersionSchema,
|
|
1047
|
+
sessionId: import_zod16.z.string(),
|
|
1048
|
+
timestamp: import_zod16.z.number()
|
|
1049
|
+
});
|
|
1050
|
+
var CliStartEventSchema = CliStreamBaseSchema.extend({
|
|
1051
|
+
type: import_zod16.z.literal(CliStreamEventType.START),
|
|
1052
|
+
payload: import_zod16.z.object({
|
|
1053
|
+
command: import_zod16.z.string(),
|
|
1054
|
+
model: import_zod16.z.string().optional(),
|
|
1055
|
+
provider: import_zod16.z.string().optional(),
|
|
1056
|
+
cwd: import_zod16.z.string().optional()
|
|
1057
|
+
})
|
|
1058
|
+
});
|
|
1059
|
+
var CliTextDeltaEventSchema = CliStreamBaseSchema.extend({
|
|
1060
|
+
type: import_zod16.z.literal(CliStreamEventType.TEXT_DELTA),
|
|
1061
|
+
payload: import_zod16.z.object({
|
|
1062
|
+
content: import_zod16.z.string()
|
|
1063
|
+
})
|
|
1064
|
+
});
|
|
1065
|
+
var CliThinkingEventSchema = CliStreamBaseSchema.extend({
|
|
1066
|
+
type: import_zod16.z.literal(CliStreamEventType.THINKING),
|
|
1067
|
+
payload: import_zod16.z.object({
|
|
1068
|
+
content: import_zod16.z.string().optional()
|
|
1069
|
+
})
|
|
1070
|
+
});
|
|
1071
|
+
var CliToolStartedEventSchema = CliStreamBaseSchema.extend({
|
|
1072
|
+
type: import_zod16.z.literal(CliStreamEventType.TOOL_STARTED),
|
|
1073
|
+
payload: import_zod16.z.object({
|
|
1074
|
+
tool: import_zod16.z.string(),
|
|
1075
|
+
toolId: import_zod16.z.string().optional(),
|
|
1076
|
+
parameters: import_zod16.z.record(import_zod16.z.string(), import_zod16.z.unknown()).optional()
|
|
1077
|
+
})
|
|
1078
|
+
});
|
|
1079
|
+
var CliToolCompletedEventSchema = CliStreamBaseSchema.extend({
|
|
1080
|
+
type: import_zod16.z.literal(CliStreamEventType.TOOL_COMPLETED),
|
|
1081
|
+
payload: import_zod16.z.object({
|
|
1082
|
+
tool: import_zod16.z.string(),
|
|
1083
|
+
toolId: import_zod16.z.string().optional(),
|
|
1084
|
+
success: import_zod16.z.boolean(),
|
|
1085
|
+
duration: import_zod16.z.number().optional(),
|
|
1086
|
+
error: import_zod16.z.string().optional()
|
|
1087
|
+
})
|
|
1088
|
+
});
|
|
1089
|
+
var CliStatusEventSchema = CliStreamBaseSchema.extend({
|
|
1090
|
+
type: import_zod16.z.literal(CliStreamEventType.STATUS),
|
|
1091
|
+
payload: import_zod16.z.object({
|
|
1092
|
+
status: import_zod16.z.string(),
|
|
1093
|
+
message: import_zod16.z.string().optional()
|
|
1094
|
+
})
|
|
1095
|
+
});
|
|
1096
|
+
var CliErrorEventSchema = CliStreamBaseSchema.extend({
|
|
1097
|
+
type: import_zod16.z.literal(CliStreamEventType.ERROR),
|
|
1098
|
+
payload: import_zod16.z.object({
|
|
1099
|
+
error: ProtocolErrorSchema
|
|
1100
|
+
})
|
|
1101
|
+
});
|
|
1102
|
+
var CliDoneEventSchema = CliStreamBaseSchema.extend({
|
|
1103
|
+
type: import_zod16.z.literal(CliStreamEventType.DONE),
|
|
1104
|
+
payload: import_zod16.z.object({
|
|
1105
|
+
exitCode: import_zod16.z.number().int(),
|
|
1106
|
+
duration: import_zod16.z.number(),
|
|
1107
|
+
toolsUsed: import_zod16.z.array(import_zod16.z.string()).optional(),
|
|
1108
|
+
tokensUsed: import_zod16.z.number().optional(),
|
|
1109
|
+
success: import_zod16.z.boolean()
|
|
1110
|
+
})
|
|
1111
|
+
});
|
|
1112
|
+
var CliStreamEventSchema = import_zod16.z.discriminatedUnion("type", [
|
|
1113
|
+
CliStartEventSchema,
|
|
1114
|
+
CliTextDeltaEventSchema,
|
|
1115
|
+
CliThinkingEventSchema,
|
|
1116
|
+
CliToolStartedEventSchema,
|
|
1117
|
+
CliToolCompletedEventSchema,
|
|
1118
|
+
CliStatusEventSchema,
|
|
1119
|
+
CliErrorEventSchema,
|
|
1120
|
+
CliDoneEventSchema
|
|
1121
|
+
]);
|
|
1122
|
+
function createCliStreamEvent(type, sessionId, payload) {
|
|
1123
|
+
return CliStreamEventSchema.parse({
|
|
1124
|
+
protocol: PROTOCOL_VERSION,
|
|
1125
|
+
type,
|
|
1126
|
+
sessionId,
|
|
1127
|
+
timestamp: Date.now(),
|
|
1128
|
+
payload
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
function parseCliStreamEvent(value) {
|
|
1132
|
+
const result = CliStreamEventSchema.safeParse(value);
|
|
1133
|
+
if (result.success) {
|
|
1134
|
+
return { success: true, data: result.data };
|
|
1135
|
+
}
|
|
1136
|
+
return { success: false, error: result.error };
|
|
1137
|
+
}
|
|
1138
|
+
// src/protocol/context.ts
|
|
1139
|
+
var import_zod17 = require("zod");
|
|
1140
|
+
var ActiveFileContextSchema = import_zod17.z.object({
|
|
1141
|
+
filePath: import_zod17.z.string(),
|
|
1142
|
+
languageId: import_zod17.z.string().optional()
|
|
1143
|
+
});
|
|
1144
|
+
var SelectionContextSchema = import_zod17.z.object({
|
|
1145
|
+
filePath: import_zod17.z.string(),
|
|
1146
|
+
languageId: import_zod17.z.string().optional(),
|
|
1147
|
+
startLine: import_zod17.z.number().int().min(0),
|
|
1148
|
+
startColumn: import_zod17.z.number().int().min(0),
|
|
1149
|
+
endLine: import_zod17.z.number().int().min(0),
|
|
1150
|
+
endColumn: import_zod17.z.number().int().min(0),
|
|
1151
|
+
text: import_zod17.z.string()
|
|
1152
|
+
});
|
|
1153
|
+
var WorkspaceContextSchema = import_zod17.z.object({
|
|
1154
|
+
rootPath: import_zod17.z.string(),
|
|
1155
|
+
name: import_zod17.z.string().optional()
|
|
1156
|
+
});
|
|
1157
|
+
var ContextPayloadSchema = import_zod17.z.object({
|
|
1158
|
+
workspace: WorkspaceContextSchema.optional(),
|
|
1159
|
+
activeFile: ActiveFileContextSchema.optional(),
|
|
1160
|
+
selection: SelectionContextSchema.optional()
|
|
1161
|
+
});
|
|
1162
|
+
// src/protocol/host-events.ts
|
|
1163
|
+
var import_zod19 = require("zod");
|
|
1164
|
+
|
|
1165
|
+
// src/protocol/session.ts
|
|
1166
|
+
var import_zod18 = require("zod");
|
|
1167
|
+
var SessionStatus = {
|
|
1168
|
+
IDLE: "idle",
|
|
1169
|
+
STARTING: "starting",
|
|
1170
|
+
RUNNING: "running",
|
|
1171
|
+
STREAMING: "streaming",
|
|
1172
|
+
COMPLETED: "completed",
|
|
1173
|
+
CANCELED: "canceled",
|
|
1174
|
+
INTERRUPTED: "interrupted",
|
|
1175
|
+
FAILED: "failed",
|
|
1176
|
+
RESUMING: "resuming"
|
|
1177
|
+
};
|
|
1178
|
+
var SessionStatusSchema = import_zod18.z.enum(SessionStatus);
|
|
1179
|
+
var SessionTransitionEvent = {
|
|
1180
|
+
CREATE_SESSION: "create_session",
|
|
1181
|
+
CLI_SPAWNED: "cli_spawned",
|
|
1182
|
+
FIRST_TEXT_DELTA: "first_text_delta",
|
|
1183
|
+
RESULT_RECEIVED: "result_received",
|
|
1184
|
+
USER_STOP: "user_stop",
|
|
1185
|
+
PROCESS_LOST: "process_lost",
|
|
1186
|
+
RESUME: "resume",
|
|
1187
|
+
ERROR: "error"
|
|
1188
|
+
};
|
|
1189
|
+
var SessionTransitionEventSchema = import_zod18.z.enum(SessionTransitionEvent);
|
|
1190
|
+
var SESSION_TRANSITIONS = [
|
|
1191
|
+
{
|
|
1192
|
+
from: SessionStatus.IDLE,
|
|
1193
|
+
event: SessionTransitionEvent.CREATE_SESSION,
|
|
1194
|
+
to: SessionStatus.STARTING
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
from: SessionStatus.STARTING,
|
|
1198
|
+
event: SessionTransitionEvent.CLI_SPAWNED,
|
|
1199
|
+
to: SessionStatus.RUNNING
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1202
|
+
from: SessionStatus.STARTING,
|
|
1203
|
+
event: SessionTransitionEvent.ERROR,
|
|
1204
|
+
to: SessionStatus.FAILED
|
|
1205
|
+
},
|
|
1206
|
+
{
|
|
1207
|
+
from: SessionStatus.RUNNING,
|
|
1208
|
+
event: SessionTransitionEvent.FIRST_TEXT_DELTA,
|
|
1209
|
+
to: SessionStatus.STREAMING
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
from: SessionStatus.RUNNING,
|
|
1213
|
+
event: SessionTransitionEvent.USER_STOP,
|
|
1214
|
+
to: SessionStatus.CANCELED
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
from: SessionStatus.RUNNING,
|
|
1218
|
+
event: SessionTransitionEvent.PROCESS_LOST,
|
|
1219
|
+
to: SessionStatus.INTERRUPTED
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
from: SessionStatus.RUNNING,
|
|
1223
|
+
event: SessionTransitionEvent.ERROR,
|
|
1224
|
+
to: SessionStatus.FAILED
|
|
1225
|
+
},
|
|
1226
|
+
{
|
|
1227
|
+
from: SessionStatus.STREAMING,
|
|
1228
|
+
event: SessionTransitionEvent.RESULT_RECEIVED,
|
|
1229
|
+
to: SessionStatus.COMPLETED
|
|
1230
|
+
},
|
|
1231
|
+
{
|
|
1232
|
+
from: SessionStatus.STREAMING,
|
|
1233
|
+
event: SessionTransitionEvent.USER_STOP,
|
|
1234
|
+
to: SessionStatus.CANCELED
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
from: SessionStatus.STREAMING,
|
|
1238
|
+
event: SessionTransitionEvent.PROCESS_LOST,
|
|
1239
|
+
to: SessionStatus.INTERRUPTED
|
|
1240
|
+
},
|
|
1241
|
+
{
|
|
1242
|
+
from: SessionStatus.STREAMING,
|
|
1243
|
+
event: SessionTransitionEvent.ERROR,
|
|
1244
|
+
to: SessionStatus.FAILED
|
|
1245
|
+
},
|
|
1246
|
+
{
|
|
1247
|
+
from: SessionStatus.INTERRUPTED,
|
|
1248
|
+
event: SessionTransitionEvent.RESUME,
|
|
1249
|
+
to: SessionStatus.RESUMING
|
|
1250
|
+
},
|
|
1251
|
+
{
|
|
1252
|
+
from: SessionStatus.RESUMING,
|
|
1253
|
+
event: SessionTransitionEvent.CLI_SPAWNED,
|
|
1254
|
+
to: SessionStatus.RUNNING
|
|
1255
|
+
},
|
|
1256
|
+
{
|
|
1257
|
+
from: SessionStatus.RESUMING,
|
|
1258
|
+
event: SessionTransitionEvent.ERROR,
|
|
1259
|
+
to: SessionStatus.FAILED
|
|
1260
|
+
},
|
|
1261
|
+
{
|
|
1262
|
+
from: SessionStatus.COMPLETED,
|
|
1263
|
+
event: SessionTransitionEvent.CREATE_SESSION,
|
|
1264
|
+
to: SessionStatus.STARTING
|
|
1265
|
+
},
|
|
1266
|
+
{
|
|
1267
|
+
from: SessionStatus.CANCELED,
|
|
1268
|
+
event: SessionTransitionEvent.CREATE_SESSION,
|
|
1269
|
+
to: SessionStatus.STARTING
|
|
1270
|
+
},
|
|
1271
|
+
{
|
|
1272
|
+
from: SessionStatus.FAILED,
|
|
1273
|
+
event: SessionTransitionEvent.CREATE_SESSION,
|
|
1274
|
+
to: SessionStatus.STARTING
|
|
1275
|
+
}
|
|
1276
|
+
];
|
|
1277
|
+
var TERMINAL_STATUSES = new Set([
|
|
1278
|
+
SessionStatus.COMPLETED,
|
|
1279
|
+
SessionStatus.CANCELED,
|
|
1280
|
+
SessionStatus.FAILED
|
|
1281
|
+
]);
|
|
1282
|
+
var SessionMetadataSchema = import_zod18.z.object({
|
|
1283
|
+
sessionId: import_zod18.z.string(),
|
|
1284
|
+
status: SessionStatusSchema,
|
|
1285
|
+
model: import_zod18.z.string().optional(),
|
|
1286
|
+
createdAt: import_zod18.z.number(),
|
|
1287
|
+
updatedAt: import_zod18.z.number(),
|
|
1288
|
+
title: import_zod18.z.string().optional()
|
|
1289
|
+
});
|
|
1290
|
+
var SessionSummarySchema = import_zod18.z.object({
|
|
1291
|
+
sessionId: import_zod18.z.string(),
|
|
1292
|
+
status: SessionStatusSchema,
|
|
1293
|
+
model: import_zod18.z.string().optional(),
|
|
1294
|
+
title: import_zod18.z.string().optional(),
|
|
1295
|
+
createdAt: import_zod18.z.number(),
|
|
1296
|
+
updatedAt: import_zod18.z.number(),
|
|
1297
|
+
messageCount: import_zod18.z.number(),
|
|
1298
|
+
toolCount: import_zod18.z.number()
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
// src/protocol/host-events.ts
|
|
1302
|
+
var HostEventType = {
|
|
1303
|
+
SESSION_STATE: "session_state",
|
|
1304
|
+
TEXT_DELTA: "text_delta",
|
|
1305
|
+
TOOL_STARTED: "tool_started",
|
|
1306
|
+
TOOL_COMPLETED: "tool_completed",
|
|
1307
|
+
THINKING: "thinking",
|
|
1308
|
+
ERROR: "error",
|
|
1309
|
+
SESSION_LIST: "session_list",
|
|
1310
|
+
SESSION_COMPLETED: "session_completed"
|
|
1311
|
+
};
|
|
1312
|
+
var HostEventTypeSchema = import_zod19.z.enum(HostEventType);
|
|
1313
|
+
var TimelineEntryKind = {
|
|
1314
|
+
MESSAGE: "message",
|
|
1315
|
+
TOOL_CALL: "tool_call",
|
|
1316
|
+
STATUS: "status",
|
|
1317
|
+
ERROR: "error",
|
|
1318
|
+
DONE: "done"
|
|
1319
|
+
};
|
|
1320
|
+
var TimelineEntryKindSchema = import_zod19.z.enum(TimelineEntryKind);
|
|
1321
|
+
var TimelineEntrySchema = import_zod19.z.object({
|
|
1322
|
+
id: import_zod19.z.string(),
|
|
1323
|
+
kind: TimelineEntryKindSchema,
|
|
1324
|
+
timestamp: import_zod19.z.number(),
|
|
1325
|
+
data: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.unknown())
|
|
1326
|
+
});
|
|
1327
|
+
var SessionStateEventSchema = import_zod19.z.object({
|
|
1328
|
+
protocol: ProtocolVersionSchema,
|
|
1329
|
+
type: import_zod19.z.literal(HostEventType.SESSION_STATE),
|
|
1330
|
+
payload: import_zod19.z.object({
|
|
1331
|
+
sessionId: import_zod19.z.string(),
|
|
1332
|
+
status: SessionStatusSchema,
|
|
1333
|
+
metadata: SessionMetadataSchema.optional(),
|
|
1334
|
+
timeline: import_zod19.z.array(TimelineEntrySchema).optional()
|
|
1335
|
+
})
|
|
1336
|
+
});
|
|
1337
|
+
var TextDeltaEventSchema = import_zod19.z.object({
|
|
1338
|
+
protocol: ProtocolVersionSchema,
|
|
1339
|
+
type: import_zod19.z.literal(HostEventType.TEXT_DELTA),
|
|
1340
|
+
payload: import_zod19.z.object({
|
|
1341
|
+
sessionId: import_zod19.z.string(),
|
|
1342
|
+
content: import_zod19.z.string()
|
|
1343
|
+
})
|
|
1344
|
+
});
|
|
1345
|
+
var ToolStartedEventSchema = import_zod19.z.object({
|
|
1346
|
+
protocol: ProtocolVersionSchema,
|
|
1347
|
+
type: import_zod19.z.literal(HostEventType.TOOL_STARTED),
|
|
1348
|
+
payload: import_zod19.z.object({
|
|
1349
|
+
sessionId: import_zod19.z.string(),
|
|
1350
|
+
tool: import_zod19.z.string(),
|
|
1351
|
+
toolId: import_zod19.z.string().optional(),
|
|
1352
|
+
parameters: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.unknown()).optional()
|
|
1353
|
+
})
|
|
1354
|
+
});
|
|
1355
|
+
var ToolCompletedEventSchema = import_zod19.z.object({
|
|
1356
|
+
protocol: ProtocolVersionSchema,
|
|
1357
|
+
type: import_zod19.z.literal(HostEventType.TOOL_COMPLETED),
|
|
1358
|
+
payload: import_zod19.z.object({
|
|
1359
|
+
sessionId: import_zod19.z.string(),
|
|
1360
|
+
tool: import_zod19.z.string(),
|
|
1361
|
+
toolId: import_zod19.z.string().optional(),
|
|
1362
|
+
result: import_zod19.z.unknown().optional(),
|
|
1363
|
+
duration: import_zod19.z.number().optional(),
|
|
1364
|
+
success: import_zod19.z.boolean(),
|
|
1365
|
+
error: import_zod19.z.string().optional()
|
|
1366
|
+
})
|
|
1367
|
+
});
|
|
1368
|
+
var ThinkingEventSchema = import_zod19.z.object({
|
|
1369
|
+
protocol: ProtocolVersionSchema,
|
|
1370
|
+
type: import_zod19.z.literal(HostEventType.THINKING),
|
|
1371
|
+
payload: import_zod19.z.object({
|
|
1372
|
+
sessionId: import_zod19.z.string(),
|
|
1373
|
+
content: import_zod19.z.string().optional()
|
|
1374
|
+
})
|
|
1375
|
+
});
|
|
1376
|
+
var ErrorEventSchema = import_zod19.z.object({
|
|
1377
|
+
protocol: ProtocolVersionSchema,
|
|
1378
|
+
type: import_zod19.z.literal(HostEventType.ERROR),
|
|
1379
|
+
payload: import_zod19.z.object({
|
|
1380
|
+
sessionId: import_zod19.z.string().optional(),
|
|
1381
|
+
error: ProtocolErrorSchema
|
|
1382
|
+
})
|
|
1383
|
+
});
|
|
1384
|
+
var SessionListEventSchema = import_zod19.z.object({
|
|
1385
|
+
protocol: ProtocolVersionSchema,
|
|
1386
|
+
type: import_zod19.z.literal(HostEventType.SESSION_LIST),
|
|
1387
|
+
payload: import_zod19.z.object({
|
|
1388
|
+
sessions: import_zod19.z.array(SessionSummarySchema)
|
|
1389
|
+
})
|
|
1390
|
+
});
|
|
1391
|
+
var SessionCompletedEventSchema = import_zod19.z.object({
|
|
1392
|
+
protocol: ProtocolVersionSchema,
|
|
1393
|
+
type: import_zod19.z.literal(HostEventType.SESSION_COMPLETED),
|
|
1394
|
+
payload: import_zod19.z.object({
|
|
1395
|
+
sessionId: import_zod19.z.string(),
|
|
1396
|
+
summary: import_zod19.z.string().optional()
|
|
1397
|
+
})
|
|
1398
|
+
});
|
|
1399
|
+
var HostEventSchema = import_zod19.z.discriminatedUnion("type", [
|
|
1400
|
+
SessionStateEventSchema,
|
|
1401
|
+
TextDeltaEventSchema,
|
|
1402
|
+
ToolStartedEventSchema,
|
|
1403
|
+
ToolCompletedEventSchema,
|
|
1404
|
+
ThinkingEventSchema,
|
|
1405
|
+
ErrorEventSchema,
|
|
1406
|
+
SessionListEventSchema,
|
|
1407
|
+
SessionCompletedEventSchema
|
|
1408
|
+
]);
|
|
1409
|
+
function createHostEvent(type, payload) {
|
|
1410
|
+
return HostEventSchema.parse({
|
|
1411
|
+
protocol: PROTOCOL_VERSION,
|
|
1412
|
+
type,
|
|
1413
|
+
payload
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// src/protocol/ui-intents.ts
|
|
1418
|
+
var import_zod20 = require("zod");
|
|
1419
|
+
var UIIntentType = {
|
|
1420
|
+
SUBMIT_PROMPT: "submit_prompt",
|
|
1421
|
+
STOP_SESSION: "stop_session",
|
|
1422
|
+
RESUME_SESSION: "resume_session",
|
|
1423
|
+
REQUEST_SESSIONS: "request_sessions",
|
|
1424
|
+
REQUEST_SESSION_DETAIL: "request_session_detail",
|
|
1425
|
+
CLEAR_SESSION: "clear_session",
|
|
1426
|
+
WEBVIEW_READY: "webview_ready"
|
|
1427
|
+
};
|
|
1428
|
+
var UIIntentTypeSchema = import_zod20.z.enum(UIIntentType);
|
|
1429
|
+
var SubmitPromptIntentSchema = import_zod20.z.object({
|
|
1430
|
+
protocol: ProtocolVersionSchema,
|
|
1431
|
+
type: import_zod20.z.literal(UIIntentType.SUBMIT_PROMPT),
|
|
1432
|
+
payload: import_zod20.z.object({
|
|
1433
|
+
text: import_zod20.z.string().min(1),
|
|
1434
|
+
context: ContextPayloadSchema.optional()
|
|
1435
|
+
})
|
|
1436
|
+
});
|
|
1437
|
+
var StopSessionIntentSchema = import_zod20.z.object({
|
|
1438
|
+
protocol: ProtocolVersionSchema,
|
|
1439
|
+
type: import_zod20.z.literal(UIIntentType.STOP_SESSION),
|
|
1440
|
+
payload: import_zod20.z.object({
|
|
1441
|
+
sessionId: import_zod20.z.string()
|
|
1442
|
+
})
|
|
1443
|
+
});
|
|
1444
|
+
var ResumeSessionIntentSchema = import_zod20.z.object({
|
|
1445
|
+
protocol: ProtocolVersionSchema,
|
|
1446
|
+
type: import_zod20.z.literal(UIIntentType.RESUME_SESSION),
|
|
1447
|
+
payload: import_zod20.z.object({
|
|
1448
|
+
sessionId: import_zod20.z.string()
|
|
1449
|
+
})
|
|
1450
|
+
});
|
|
1451
|
+
var RequestSessionsIntentSchema = import_zod20.z.object({
|
|
1452
|
+
protocol: ProtocolVersionSchema,
|
|
1453
|
+
type: import_zod20.z.literal(UIIntentType.REQUEST_SESSIONS),
|
|
1454
|
+
payload: import_zod20.z.object({}).optional()
|
|
1455
|
+
});
|
|
1456
|
+
var RequestSessionDetailIntentSchema = import_zod20.z.object({
|
|
1457
|
+
protocol: ProtocolVersionSchema,
|
|
1458
|
+
type: import_zod20.z.literal(UIIntentType.REQUEST_SESSION_DETAIL),
|
|
1459
|
+
payload: import_zod20.z.object({
|
|
1460
|
+
sessionId: import_zod20.z.string()
|
|
1461
|
+
})
|
|
1462
|
+
});
|
|
1463
|
+
var ClearSessionIntentSchema = import_zod20.z.object({
|
|
1464
|
+
protocol: ProtocolVersionSchema,
|
|
1465
|
+
type: import_zod20.z.literal(UIIntentType.CLEAR_SESSION),
|
|
1466
|
+
payload: import_zod20.z.object({
|
|
1467
|
+
sessionId: import_zod20.z.string()
|
|
1468
|
+
})
|
|
1469
|
+
});
|
|
1470
|
+
var WebviewReadyIntentSchema = import_zod20.z.object({
|
|
1471
|
+
protocol: ProtocolVersionSchema,
|
|
1472
|
+
type: import_zod20.z.literal(UIIntentType.WEBVIEW_READY),
|
|
1473
|
+
payload: import_zod20.z.object({}).optional()
|
|
1474
|
+
});
|
|
1475
|
+
var UIIntentSchema = import_zod20.z.discriminatedUnion("type", [
|
|
1476
|
+
SubmitPromptIntentSchema,
|
|
1477
|
+
StopSessionIntentSchema,
|
|
1478
|
+
ResumeSessionIntentSchema,
|
|
1479
|
+
RequestSessionsIntentSchema,
|
|
1480
|
+
RequestSessionDetailIntentSchema,
|
|
1481
|
+
ClearSessionIntentSchema,
|
|
1482
|
+
WebviewReadyIntentSchema
|
|
1483
|
+
]);
|
|
1484
|
+
function createUIIntent(type, payload) {
|
|
1485
|
+
return UIIntentSchema.parse({
|
|
1486
|
+
protocol: PROTOCOL_VERSION,
|
|
1487
|
+
type,
|
|
1488
|
+
payload
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
// src/protocol/helpers.ts
|
|
1493
|
+
function parseUIIntent(message) {
|
|
1494
|
+
return UIIntentSchema.safeParse(message);
|
|
1495
|
+
}
|
|
1496
|
+
function parseHostEvent(message) {
|
|
1497
|
+
return HostEventSchema.safeParse(message);
|
|
1498
|
+
}
|
|
1499
|
+
function isUIIntentType(intent, type) {
|
|
1500
|
+
return intent.type === type;
|
|
1501
|
+
}
|
|
1502
|
+
function isHostEventType(event, type) {
|
|
1503
|
+
return event.type === type;
|
|
1504
|
+
}
|
|
1505
|
+
function isValidTransition(from, event) {
|
|
1506
|
+
return SESSION_TRANSITIONS.some((t) => t.from === from && t.event === event);
|
|
1507
|
+
}
|
|
1508
|
+
function getNextStatus(from, event) {
|
|
1509
|
+
const transition = SESSION_TRANSITIONS.find((t) => t.from === from && t.event === event);
|
|
1510
|
+
return transition?.to ?? null;
|
|
1511
|
+
}
|
|
1512
|
+
function isTerminalStatus(status) {
|
|
1513
|
+
return TERMINAL_STATUSES.has(status);
|
|
1514
|
+
}
|
|
1515
|
+
function createProtocolError(code, message, options) {
|
|
1516
|
+
return {
|
|
1517
|
+
code,
|
|
1518
|
+
message,
|
|
1519
|
+
details: options?.details,
|
|
1520
|
+
recoverable: options?.recoverable ?? false
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
function createErrorEvent(code, message, options) {
|
|
1524
|
+
return {
|
|
1525
|
+
protocol: PROTOCOL_VERSION,
|
|
1526
|
+
type: HostEventType.ERROR,
|
|
1527
|
+
payload: {
|
|
1528
|
+
sessionId: options?.sessionId,
|
|
1529
|
+
error: createProtocolError(code, message, {
|
|
1530
|
+
details: options?.details,
|
|
1531
|
+
recoverable: options?.recoverable
|
|
1532
|
+
})
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
}
|