@serviceme/devtools-protocol 0.0.3
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/LICENSE.md +46 -0
- package/README.md +21 -0
- package/dist/bridge.d.ts +159 -0
- package/dist/bridge.js +139 -0
- package/dist/bridge.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.js +31 -0
- package/dist/cli.js.map +1 -0
- package/dist/env.d.ts +12 -0
- package/dist/env.js +32 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.js +98 -0
- package/dist/errors.js.map +1 -0
- package/dist/image.d.ts +31 -0
- package/dist/image.js +43 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.mts +358 -0
- package/dist/index.d.ts +358 -0
- package/dist/index.js +565 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +473 -0
- package/dist/json.d.ts +20 -0
- package/dist/json.js +33 -0
- package/dist/json.js.map +1 -0
- package/dist/metadata.d.ts +10 -0
- package/dist/metadata.js +11 -0
- package/dist/metadata.js.map +1 -0
- package/dist/opencode.d.ts +46 -0
- package/dist/opencode.js +58 -0
- package/dist/opencode.js.map +1 -0
- package/dist/project.d.ts +32 -0
- package/dist/project.js +37 -0
- package/dist/project.js.map +1 -0
- package/package.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BRIDGE_EVENTS: () => BRIDGE_EVENTS,
|
|
24
|
+
BRIDGE_METHODS: () => BRIDGE_METHODS,
|
|
25
|
+
DEFAULT_JSON_SORT_OPTIONS: () => DEFAULT_JSON_SORT_OPTIONS,
|
|
26
|
+
JSON_SORT_ALGORITHMS: () => JSON_SORT_ALGORITHMS,
|
|
27
|
+
JSON_SORT_ORDERS: () => JSON_SORT_ORDERS,
|
|
28
|
+
KNOWN_ENVIRONMENT_TOOLS: () => KNOWN_ENVIRONMENT_TOOLS,
|
|
29
|
+
SERVICEME_CLI_CAPABILITIES: () => SERVICEME_CLI_CAPABILITIES,
|
|
30
|
+
SERVICEME_CLI_NAME: () => SERVICEME_CLI_NAME,
|
|
31
|
+
SERVICEME_CLI_SCHEMA_VERSION: () => SERVICEME_CLI_SCHEMA_VERSION,
|
|
32
|
+
SERVICEME_CLI_VERSION: () => SERVICEME_CLI_VERSION,
|
|
33
|
+
SERVICEME_ERROR_CODES: () => SERVICEME_ERROR_CODES,
|
|
34
|
+
SERVICEME_IMAGE_FORMATS: () => SERVICEME_IMAGE_FORMATS,
|
|
35
|
+
SERVICEME_PROTOCOL_VERSION: () => SERVICEME_PROTOCOL_VERSION,
|
|
36
|
+
ServicemeProtocolError: () => ServicemeProtocolError,
|
|
37
|
+
createCliFailure: () => createCliFailure,
|
|
38
|
+
createCliSuccess: () => createCliSuccess,
|
|
39
|
+
createServicemeError: () => createServicemeError,
|
|
40
|
+
getBridgeEventParamsValidator: () => getBridgeEventParamsValidator,
|
|
41
|
+
getBridgeResultValidator: () => getBridgeResultValidator,
|
|
42
|
+
isAgentSessionStatus: () => isAgentSessionStatus,
|
|
43
|
+
isBridgeCapabilities: () => isBridgeCapabilities,
|
|
44
|
+
isBridgeEvent: () => isBridgeEvent,
|
|
45
|
+
isBridgeEventName: () => isBridgeEventName,
|
|
46
|
+
isBridgeMethod: () => isBridgeMethod,
|
|
47
|
+
isBridgeRequest: () => isBridgeRequest,
|
|
48
|
+
isBridgeResponse: () => isBridgeResponse,
|
|
49
|
+
isCliEnvelope: () => isCliEnvelope,
|
|
50
|
+
isEnvironmentCheckResult: () => isEnvironmentCheckResult,
|
|
51
|
+
isJsonOutputResult: () => isJsonOutputResult,
|
|
52
|
+
isJsonSortAlgorithm: () => isJsonSortAlgorithm,
|
|
53
|
+
isJsonSortOptions: () => isJsonSortOptions,
|
|
54
|
+
isJsonSortOrder: () => isJsonSortOrder,
|
|
55
|
+
isJsonValidationResult: () => isJsonValidationResult,
|
|
56
|
+
isKnownEnvironmentTool: () => isKnownEnvironmentTool,
|
|
57
|
+
isOpenCodeAgentEvent: () => isOpenCodeAgentEvent,
|
|
58
|
+
isOpenCodeServerState: () => isOpenCodeServerState,
|
|
59
|
+
isOpenCodeSessionAbortResult: () => isOpenCodeSessionAbortResult,
|
|
60
|
+
isOpenCodeSessionCompletedEvent: () => isOpenCodeSessionCompletedEvent,
|
|
61
|
+
isOpenCodeSessionCreateResult: () => isOpenCodeSessionCreateResult,
|
|
62
|
+
isOpenCodeSessionDisposeResult: () => isOpenCodeSessionDisposeResult,
|
|
63
|
+
isOpenCodeSessionErrorEvent: () => isOpenCodeSessionErrorEvent,
|
|
64
|
+
isOpenCodeSessionEventParams: () => isOpenCodeSessionEventParams,
|
|
65
|
+
isOpenCodeSessionMessageEvent: () => isOpenCodeSessionMessageEvent,
|
|
66
|
+
isOpenCodeSessionProgressEvent: () => isOpenCodeSessionProgressEvent,
|
|
67
|
+
isOpenCodeSessionPromptResult: () => isOpenCodeSessionPromptResult,
|
|
68
|
+
isOpenCodeSessionStatusEvent: () => isOpenCodeSessionStatusEvent,
|
|
69
|
+
isOpenCodeSessionStatusResult: () => isOpenCodeSessionStatusResult,
|
|
70
|
+
isRetryableErrorCode: () => isRetryableErrorCode,
|
|
71
|
+
isServiceMeImageCompressOptions: () => isServiceMeImageCompressOptions,
|
|
72
|
+
isServiceMeImageCompressResult: () => isServiceMeImageCompressResult,
|
|
73
|
+
isServiceMeImageFormat: () => isServiceMeImageFormat,
|
|
74
|
+
isServiceMeImageInfo: () => isServiceMeImageInfo,
|
|
75
|
+
isServiceMeImageValidationResult: () => isServiceMeImageValidationResult,
|
|
76
|
+
isServiceMeProjectExtractTemplateInput: () => isServiceMeProjectExtractTemplateInput,
|
|
77
|
+
isServiceMeProjectExtractTemplateResult: () => isServiceMeProjectExtractTemplateResult,
|
|
78
|
+
isServiceMeProjectGitInitResult: () => isServiceMeProjectGitInitResult,
|
|
79
|
+
isServiceMeProjectInstallDepsResult: () => isServiceMeProjectInstallDepsResult,
|
|
80
|
+
isServiceMeProjectMakeScriptsExecutableResult: () => isServiceMeProjectMakeScriptsExecutableResult,
|
|
81
|
+
isServiceMeProjectScaffoldPruneResult: () => isServiceMeProjectScaffoldPruneResult,
|
|
82
|
+
isServicemeErrorCode: () => isServicemeErrorCode,
|
|
83
|
+
isServicemeErrorDetails: () => isServicemeErrorDetails,
|
|
84
|
+
isSystemHelloResult: () => isSystemHelloResult,
|
|
85
|
+
isSystemPingResult: () => isSystemPingResult,
|
|
86
|
+
isSystemShutdownResult: () => isSystemShutdownResult,
|
|
87
|
+
isToolCheckResult: () => isToolCheckResult,
|
|
88
|
+
normalizeServicemeError: () => normalizeServicemeError
|
|
89
|
+
});
|
|
90
|
+
module.exports = __toCommonJS(index_exports);
|
|
91
|
+
|
|
92
|
+
// src/opencode.ts
|
|
93
|
+
function isRecord(value) {
|
|
94
|
+
return typeof value === "object" && value !== null;
|
|
95
|
+
}
|
|
96
|
+
function isAgentSessionStatus(value) {
|
|
97
|
+
return value === "idle" || value === "running" || value === "needs-input" || value === "completed" || value === "failed" || value === "aborted";
|
|
98
|
+
}
|
|
99
|
+
function isOpenCodeServerState(value) {
|
|
100
|
+
return isRecord(value) && typeof value.available === "boolean" && typeof value.running === "boolean" && typeof value.healthy === "boolean" && typeof value.installUrl === "string" && (value.pid === void 0 || typeof value.pid === "number") && (value.port === void 0 || typeof value.port === "number");
|
|
101
|
+
}
|
|
102
|
+
function isMetadata(value) {
|
|
103
|
+
return value === void 0 || isRecord(value);
|
|
104
|
+
}
|
|
105
|
+
function isOpenCodeSessionStatusEvent(value) {
|
|
106
|
+
return isRecord(value) && value.type === "status" && isAgentSessionStatus(value.status) && isMetadata(value.metadata);
|
|
107
|
+
}
|
|
108
|
+
function isOpenCodeSessionProgressEvent(value) {
|
|
109
|
+
return isRecord(value) && value.type === "progress" && typeof value.text === "string" && isMetadata(value.metadata);
|
|
110
|
+
}
|
|
111
|
+
function isOpenCodeSessionMessageEvent(value) {
|
|
112
|
+
return isRecord(value) && value.type === "message" && typeof value.text === "string" && isMetadata(value.metadata);
|
|
113
|
+
}
|
|
114
|
+
function isOpenCodeSessionErrorEvent(value) {
|
|
115
|
+
return isRecord(value) && value.type === "error" && typeof value.text === "string" && isMetadata(value.metadata);
|
|
116
|
+
}
|
|
117
|
+
function isOpenCodeSessionCompletedEvent(value) {
|
|
118
|
+
return isRecord(value) && value.type === "completed" && isMetadata(value.metadata);
|
|
119
|
+
}
|
|
120
|
+
function isOpenCodeAgentEvent(value) {
|
|
121
|
+
return isOpenCodeSessionStatusEvent(value) || isOpenCodeSessionProgressEvent(value) || isOpenCodeSessionMessageEvent(value) || isOpenCodeSessionErrorEvent(value) || isOpenCodeSessionCompletedEvent(value);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/bridge.ts
|
|
125
|
+
var SERVICEME_PROTOCOL_VERSION = 1;
|
|
126
|
+
function isRecord2(value) {
|
|
127
|
+
return typeof value === "object" && value !== null;
|
|
128
|
+
}
|
|
129
|
+
function isBridgeCapabilities(value) {
|
|
130
|
+
return isRecord2(value) && value.bridge === true && value.opencode === 1 && value.json === 1 && value.env === 1;
|
|
131
|
+
}
|
|
132
|
+
var BRIDGE_METHODS = [
|
|
133
|
+
"system.hello",
|
|
134
|
+
"system.ping",
|
|
135
|
+
"system.shutdown",
|
|
136
|
+
"opencode.server.ensure",
|
|
137
|
+
"opencode.server.status",
|
|
138
|
+
"opencode.session.create",
|
|
139
|
+
"opencode.session.prompt",
|
|
140
|
+
"opencode.session.status",
|
|
141
|
+
"opencode.session.abort",
|
|
142
|
+
"opencode.session.dispose"
|
|
143
|
+
];
|
|
144
|
+
var BRIDGE_EVENTS = ["opencode.session.event"];
|
|
145
|
+
function isSystemHelloResult(value) {
|
|
146
|
+
return isRecord2(value) && typeof value.cliVersion === "string" && value.protocolVersion === SERVICEME_PROTOCOL_VERSION && isBridgeCapabilities(value.capabilities) && typeof value.pid === "number";
|
|
147
|
+
}
|
|
148
|
+
function isSystemPingResult(value) {
|
|
149
|
+
return isRecord2(value) && typeof value.now === "string";
|
|
150
|
+
}
|
|
151
|
+
function isSystemShutdownResult(value) {
|
|
152
|
+
return isRecord2(value) && value.shuttingDown === true;
|
|
153
|
+
}
|
|
154
|
+
function isOpenCodeSessionCreateResult(value) {
|
|
155
|
+
return isRecord2(value) && typeof value.sessionId === "string" && (value.title === void 0 || typeof value.title === "string") && isAgentSessionStatus(value.status);
|
|
156
|
+
}
|
|
157
|
+
function isOpenCodeSessionPromptResult(value) {
|
|
158
|
+
return isRecord2(value) && value.accepted === true && typeof value.sessionId === "string" && typeof value.promptId === "string";
|
|
159
|
+
}
|
|
160
|
+
function isOpenCodeSessionStatusResult(value) {
|
|
161
|
+
return isRecord2(value) && typeof value.sessionId === "string" && isAgentSessionStatus(value.status);
|
|
162
|
+
}
|
|
163
|
+
function isOpenCodeSessionAbortResult(value) {
|
|
164
|
+
return isRecord2(value) && value.aborted === true && typeof value.sessionId === "string";
|
|
165
|
+
}
|
|
166
|
+
function isOpenCodeSessionDisposeResult(value) {
|
|
167
|
+
return isRecord2(value) && value.disposed === true && typeof value.sessionId === "string";
|
|
168
|
+
}
|
|
169
|
+
function getBridgeResultValidator(method) {
|
|
170
|
+
switch (method) {
|
|
171
|
+
case "system.hello":
|
|
172
|
+
return isSystemHelloResult;
|
|
173
|
+
case "system.ping":
|
|
174
|
+
return isSystemPingResult;
|
|
175
|
+
case "system.shutdown":
|
|
176
|
+
return isSystemShutdownResult;
|
|
177
|
+
case "opencode.server.ensure":
|
|
178
|
+
case "opencode.server.status":
|
|
179
|
+
return isOpenCodeServerState;
|
|
180
|
+
case "opencode.session.create":
|
|
181
|
+
return isOpenCodeSessionCreateResult;
|
|
182
|
+
case "opencode.session.prompt":
|
|
183
|
+
return isOpenCodeSessionPromptResult;
|
|
184
|
+
case "opencode.session.status":
|
|
185
|
+
return isOpenCodeSessionStatusResult;
|
|
186
|
+
case "opencode.session.abort":
|
|
187
|
+
return isOpenCodeSessionAbortResult;
|
|
188
|
+
case "opencode.session.dispose":
|
|
189
|
+
return isOpenCodeSessionDisposeResult;
|
|
190
|
+
default:
|
|
191
|
+
return void 0;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function isOpenCodeSessionEventParams(value) {
|
|
195
|
+
return isRecord2(value) && typeof value.sessionId === "string" && (value.promptId === void 0 || typeof value.promptId === "string") && isOpenCodeAgentEvent(value.payload);
|
|
196
|
+
}
|
|
197
|
+
function getBridgeEventParamsValidator(event) {
|
|
198
|
+
switch (event) {
|
|
199
|
+
case "opencode.session.event":
|
|
200
|
+
return isOpenCodeSessionEventParams;
|
|
201
|
+
default:
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function isBridgeMethod(value) {
|
|
206
|
+
return typeof value === "string" && BRIDGE_METHODS.includes(value);
|
|
207
|
+
}
|
|
208
|
+
function isBridgeEventName(value) {
|
|
209
|
+
return typeof value === "string" && BRIDGE_EVENTS.includes(value);
|
|
210
|
+
}
|
|
211
|
+
function isBridgeRequest(value) {
|
|
212
|
+
if (!isRecord2(value)) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return value.protocolVersion === SERVICEME_PROTOCOL_VERSION && value.kind === "request" && typeof value.id === "string" && isBridgeMethod(value.method) && "params" in value;
|
|
216
|
+
}
|
|
217
|
+
function isBridgeResponse(value) {
|
|
218
|
+
if (!isRecord2(value)) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
if (value.protocolVersion !== SERVICEME_PROTOCOL_VERSION || value.kind !== "response" || typeof value.id !== "string" || typeof value.ok !== "boolean") {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
if (value.ok) {
|
|
225
|
+
return "result" in value;
|
|
226
|
+
}
|
|
227
|
+
return "error" in value;
|
|
228
|
+
}
|
|
229
|
+
function isBridgeEvent(value) {
|
|
230
|
+
if (!isRecord2(value)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
return value.protocolVersion === SERVICEME_PROTOCOL_VERSION && value.kind === "event" && isBridgeEventName(value.event) && "params" in value;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/cli.ts
|
|
237
|
+
var SERVICEME_CLI_SCHEMA_VERSION = 1;
|
|
238
|
+
function isRecord3(value) {
|
|
239
|
+
return typeof value === "object" && value !== null;
|
|
240
|
+
}
|
|
241
|
+
function createCliSuccess(data) {
|
|
242
|
+
return {
|
|
243
|
+
schemaVersion: SERVICEME_CLI_SCHEMA_VERSION,
|
|
244
|
+
ok: true,
|
|
245
|
+
data
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function createCliFailure(error) {
|
|
249
|
+
return {
|
|
250
|
+
schemaVersion: SERVICEME_CLI_SCHEMA_VERSION,
|
|
251
|
+
ok: false,
|
|
252
|
+
error
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function isCliEnvelope(value) {
|
|
256
|
+
if (!isRecord3(value)) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
if (value.schemaVersion !== SERVICEME_CLI_SCHEMA_VERSION || typeof value.ok !== "boolean") {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
if (value.ok) {
|
|
263
|
+
return "data" in value;
|
|
264
|
+
}
|
|
265
|
+
return "error" in value;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/env.ts
|
|
269
|
+
var KNOWN_ENVIRONMENT_TOOLS = [
|
|
270
|
+
"git",
|
|
271
|
+
"node",
|
|
272
|
+
"npm",
|
|
273
|
+
"pnpm",
|
|
274
|
+
"nvm",
|
|
275
|
+
"nrm",
|
|
276
|
+
"dotnet",
|
|
277
|
+
"nuget"
|
|
278
|
+
];
|
|
279
|
+
function isRecord4(value) {
|
|
280
|
+
return typeof value === "object" && value !== null;
|
|
281
|
+
}
|
|
282
|
+
function isKnownEnvironmentTool(value) {
|
|
283
|
+
return KNOWN_ENVIRONMENT_TOOLS.includes(value);
|
|
284
|
+
}
|
|
285
|
+
function isToolCheckResult(value) {
|
|
286
|
+
if (!isRecord4(value)) {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
return typeof value.installed === "boolean" && (value.version === void 0 || typeof value.version === "string") && (value.path === void 0 || typeof value.path === "string") && (value.error === void 0 || typeof value.error === "string");
|
|
290
|
+
}
|
|
291
|
+
function isEnvironmentCheckResult(value) {
|
|
292
|
+
if (!isRecord4(value)) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
return KNOWN_ENVIRONMENT_TOOLS.every((tool) => isToolCheckResult(value[tool]));
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// src/errors.ts
|
|
299
|
+
var SERVICEME_ERROR_CODES = [
|
|
300
|
+
"protocol_mismatch",
|
|
301
|
+
"cli_not_found",
|
|
302
|
+
"cli_start_failed",
|
|
303
|
+
"command_timeout",
|
|
304
|
+
"request_cancelled",
|
|
305
|
+
"invalid_params",
|
|
306
|
+
"opencode_not_installed",
|
|
307
|
+
"opencode_startup_timeout",
|
|
308
|
+
"opencode_request_failed",
|
|
309
|
+
"opencode_backend_not_running",
|
|
310
|
+
"opencode_session_not_found",
|
|
311
|
+
"json_invalid_input",
|
|
312
|
+
"env_tool_not_found",
|
|
313
|
+
"internal_error"
|
|
314
|
+
];
|
|
315
|
+
var RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
316
|
+
"command_timeout",
|
|
317
|
+
"request_cancelled",
|
|
318
|
+
"opencode_startup_timeout",
|
|
319
|
+
"opencode_request_failed",
|
|
320
|
+
"opencode_backend_not_running",
|
|
321
|
+
"internal_error"
|
|
322
|
+
]);
|
|
323
|
+
function isRecord5(value) {
|
|
324
|
+
return typeof value === "object" && value !== null;
|
|
325
|
+
}
|
|
326
|
+
function isServicemeErrorCode(value) {
|
|
327
|
+
return typeof value === "string" && SERVICEME_ERROR_CODES.includes(value);
|
|
328
|
+
}
|
|
329
|
+
function isServicemeErrorDetails(value) {
|
|
330
|
+
if (!isRecord5(value)) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
return isServicemeErrorCode(value.code) && typeof value.message === "string" && typeof value.retryable === "boolean";
|
|
334
|
+
}
|
|
335
|
+
function isRetryableErrorCode(code) {
|
|
336
|
+
return RETRYABLE_ERROR_CODES.has(code);
|
|
337
|
+
}
|
|
338
|
+
var ServicemeProtocolError = class extends Error {
|
|
339
|
+
constructor(input) {
|
|
340
|
+
super(input.message);
|
|
341
|
+
this.name = "ServicemeProtocolError";
|
|
342
|
+
this.code = input.code;
|
|
343
|
+
this.retryable = input.retryable ?? isRetryableErrorCode(input.code);
|
|
344
|
+
this.details = input.details;
|
|
345
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
346
|
+
}
|
|
347
|
+
toJSON() {
|
|
348
|
+
return {
|
|
349
|
+
code: this.code,
|
|
350
|
+
message: this.message,
|
|
351
|
+
retryable: this.retryable,
|
|
352
|
+
details: this.details
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
function createServicemeError(code, message, details) {
|
|
357
|
+
return new ServicemeProtocolError({
|
|
358
|
+
code,
|
|
359
|
+
message,
|
|
360
|
+
details
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
function normalizeServicemeError(error, fallbackCode = "internal_error") {
|
|
364
|
+
if (error instanceof ServicemeProtocolError) {
|
|
365
|
+
return error.toJSON();
|
|
366
|
+
}
|
|
367
|
+
if (isServicemeErrorDetails(error)) {
|
|
368
|
+
return error;
|
|
369
|
+
}
|
|
370
|
+
if (isRecord5(error)) {
|
|
371
|
+
const code = isServicemeErrorCode(error.code) ? error.code : fallbackCode;
|
|
372
|
+
const message = typeof error.message === "string" ? error.message : "Unexpected serviceme error.";
|
|
373
|
+
const retryable = typeof error.retryable === "boolean" ? error.retryable : isRetryableErrorCode(code);
|
|
374
|
+
return {
|
|
375
|
+
code,
|
|
376
|
+
message,
|
|
377
|
+
retryable,
|
|
378
|
+
details: error.details
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
if (error instanceof Error) {
|
|
382
|
+
return {
|
|
383
|
+
code: fallbackCode,
|
|
384
|
+
message: error.message,
|
|
385
|
+
retryable: isRetryableErrorCode(fallbackCode)
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
code: fallbackCode,
|
|
390
|
+
message: typeof error === "string" ? error : "Unexpected serviceme error.",
|
|
391
|
+
retryable: isRetryableErrorCode(fallbackCode)
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// src/image.ts
|
|
396
|
+
var SERVICEME_IMAGE_FORMATS = ["jpeg", "png", "webp"];
|
|
397
|
+
function isRecord6(value) {
|
|
398
|
+
return typeof value === "object" && value !== null;
|
|
399
|
+
}
|
|
400
|
+
function isServiceMeImageFormat(value) {
|
|
401
|
+
return typeof value === "string" && SERVICEME_IMAGE_FORMATS.includes(value);
|
|
402
|
+
}
|
|
403
|
+
function isServiceMeImageCompressOptions(value) {
|
|
404
|
+
if (!isRecord6(value)) {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
return typeof value.quality === "number" && typeof value.replaceOriginImage === "boolean" && (value.outputPath === void 0 || typeof value.outputPath === "string") && (value.format === void 0 || isServiceMeImageFormat(value.format)) && (value.sharpModulePath === void 0 || typeof value.sharpModulePath === "string") && (value.minimumCompressionRatio === void 0 || typeof value.minimumCompressionRatio === "number");
|
|
408
|
+
}
|
|
409
|
+
function isServiceMeImageCompressResult(value) {
|
|
410
|
+
if (!isRecord6(value)) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
return typeof value.originalSize === "number" && typeof value.compressedSize === "number" && typeof value.compressionRatio === "number" && typeof value.outputPath === "string";
|
|
414
|
+
}
|
|
415
|
+
function isServiceMeImageInfo(value) {
|
|
416
|
+
if (!isRecord6(value)) {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
return typeof value.width === "number" && typeof value.height === "number" && typeof value.format === "string" && typeof value.size === "number" && (value.colorSpace === void 0 || typeof value.colorSpace === "string");
|
|
420
|
+
}
|
|
421
|
+
function isServiceMeImageValidationResult(value) {
|
|
422
|
+
return isRecord6(value) && typeof value.valid === "boolean";
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/json.ts
|
|
426
|
+
var JSON_SORT_ALGORITHMS = [
|
|
427
|
+
"default",
|
|
428
|
+
"keyLength",
|
|
429
|
+
"alphaNum",
|
|
430
|
+
"values",
|
|
431
|
+
"type"
|
|
432
|
+
];
|
|
433
|
+
var JSON_SORT_ORDERS = ["asc", "desc"];
|
|
434
|
+
var DEFAULT_JSON_SORT_OPTIONS = {
|
|
435
|
+
sortOrder: "asc",
|
|
436
|
+
sortAlgo: "default"
|
|
437
|
+
};
|
|
438
|
+
function isRecord7(value) {
|
|
439
|
+
return typeof value === "object" && value !== null;
|
|
440
|
+
}
|
|
441
|
+
function isJsonSortAlgorithm(value) {
|
|
442
|
+
return typeof value === "string" && JSON_SORT_ALGORITHMS.includes(value);
|
|
443
|
+
}
|
|
444
|
+
function isJsonSortOrder(value) {
|
|
445
|
+
return typeof value === "string" && JSON_SORT_ORDERS.includes(value);
|
|
446
|
+
}
|
|
447
|
+
function isJsonSortOptions(value) {
|
|
448
|
+
return isRecord7(value) && isJsonSortOrder(value.sortOrder) && isJsonSortAlgorithm(value.sortAlgo);
|
|
449
|
+
}
|
|
450
|
+
function isJsonValidationResult(value) {
|
|
451
|
+
return isRecord7(value) && typeof value.valid === "boolean" && (value.error === void 0 || typeof value.error === "string");
|
|
452
|
+
}
|
|
453
|
+
function isJsonOutputResult(value) {
|
|
454
|
+
return isRecord7(value) && typeof value.output === "string";
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// src/metadata.ts
|
|
458
|
+
var SERVICEME_CLI_NAME = "serviceme";
|
|
459
|
+
var SERVICEME_CLI_VERSION = "0.0.1";
|
|
460
|
+
var SERVICEME_CLI_CAPABILITIES = {
|
|
461
|
+
bridge: true,
|
|
462
|
+
opencode: 1,
|
|
463
|
+
json: 1,
|
|
464
|
+
env: 1,
|
|
465
|
+
image: 1,
|
|
466
|
+
project: 1
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/project.ts
|
|
470
|
+
function isRecord8(value) {
|
|
471
|
+
return typeof value === "object" && value !== null;
|
|
472
|
+
}
|
|
473
|
+
function isServiceMeProjectScaffoldPruneResult(value) {
|
|
474
|
+
if (!isRecord8(value)) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
return typeof value.applied === "boolean" && typeof value.preset === "string" && Array.isArray(value.commands) && value.commands.every((command) => typeof command === "string");
|
|
478
|
+
}
|
|
479
|
+
function isServiceMeProjectGitInitResult(value) {
|
|
480
|
+
return isRecord8(value) && typeof value.initialized === "boolean" && typeof value.command === "string";
|
|
481
|
+
}
|
|
482
|
+
function isServiceMeProjectMakeScriptsExecutableResult(value) {
|
|
483
|
+
if (!isRecord8(value)) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
return typeof value.processedCount === "number" && typeof value.updatedCount === "number" && typeof value.platform === "string" && Array.isArray(value.scripts) && value.scripts.every((script) => typeof script === "string");
|
|
487
|
+
}
|
|
488
|
+
function isServiceMeProjectInstallDepsResult(value) {
|
|
489
|
+
return isRecord8(value) && typeof value.installed === "boolean" && typeof value.command === "string";
|
|
490
|
+
}
|
|
491
|
+
function isServiceMeProjectExtractTemplateInput(value) {
|
|
492
|
+
return isRecord8(value) && typeof value.extractedDirName === "string" && typeof value.projectFilePattern === "string";
|
|
493
|
+
}
|
|
494
|
+
function isServiceMeProjectExtractTemplateResult(value) {
|
|
495
|
+
return isRecord8(value) && typeof value.actualDirName === "string";
|
|
496
|
+
}
|
|
497
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
498
|
+
0 && (module.exports = {
|
|
499
|
+
BRIDGE_EVENTS,
|
|
500
|
+
BRIDGE_METHODS,
|
|
501
|
+
DEFAULT_JSON_SORT_OPTIONS,
|
|
502
|
+
JSON_SORT_ALGORITHMS,
|
|
503
|
+
JSON_SORT_ORDERS,
|
|
504
|
+
KNOWN_ENVIRONMENT_TOOLS,
|
|
505
|
+
SERVICEME_CLI_CAPABILITIES,
|
|
506
|
+
SERVICEME_CLI_NAME,
|
|
507
|
+
SERVICEME_CLI_SCHEMA_VERSION,
|
|
508
|
+
SERVICEME_CLI_VERSION,
|
|
509
|
+
SERVICEME_ERROR_CODES,
|
|
510
|
+
SERVICEME_IMAGE_FORMATS,
|
|
511
|
+
SERVICEME_PROTOCOL_VERSION,
|
|
512
|
+
ServicemeProtocolError,
|
|
513
|
+
createCliFailure,
|
|
514
|
+
createCliSuccess,
|
|
515
|
+
createServicemeError,
|
|
516
|
+
getBridgeEventParamsValidator,
|
|
517
|
+
getBridgeResultValidator,
|
|
518
|
+
isAgentSessionStatus,
|
|
519
|
+
isBridgeCapabilities,
|
|
520
|
+
isBridgeEvent,
|
|
521
|
+
isBridgeEventName,
|
|
522
|
+
isBridgeMethod,
|
|
523
|
+
isBridgeRequest,
|
|
524
|
+
isBridgeResponse,
|
|
525
|
+
isCliEnvelope,
|
|
526
|
+
isEnvironmentCheckResult,
|
|
527
|
+
isJsonOutputResult,
|
|
528
|
+
isJsonSortAlgorithm,
|
|
529
|
+
isJsonSortOptions,
|
|
530
|
+
isJsonSortOrder,
|
|
531
|
+
isJsonValidationResult,
|
|
532
|
+
isKnownEnvironmentTool,
|
|
533
|
+
isOpenCodeAgentEvent,
|
|
534
|
+
isOpenCodeServerState,
|
|
535
|
+
isOpenCodeSessionAbortResult,
|
|
536
|
+
isOpenCodeSessionCompletedEvent,
|
|
537
|
+
isOpenCodeSessionCreateResult,
|
|
538
|
+
isOpenCodeSessionDisposeResult,
|
|
539
|
+
isOpenCodeSessionErrorEvent,
|
|
540
|
+
isOpenCodeSessionEventParams,
|
|
541
|
+
isOpenCodeSessionMessageEvent,
|
|
542
|
+
isOpenCodeSessionProgressEvent,
|
|
543
|
+
isOpenCodeSessionPromptResult,
|
|
544
|
+
isOpenCodeSessionStatusEvent,
|
|
545
|
+
isOpenCodeSessionStatusResult,
|
|
546
|
+
isRetryableErrorCode,
|
|
547
|
+
isServiceMeImageCompressOptions,
|
|
548
|
+
isServiceMeImageCompressResult,
|
|
549
|
+
isServiceMeImageFormat,
|
|
550
|
+
isServiceMeImageInfo,
|
|
551
|
+
isServiceMeImageValidationResult,
|
|
552
|
+
isServiceMeProjectExtractTemplateInput,
|
|
553
|
+
isServiceMeProjectExtractTemplateResult,
|
|
554
|
+
isServiceMeProjectGitInitResult,
|
|
555
|
+
isServiceMeProjectInstallDepsResult,
|
|
556
|
+
isServiceMeProjectMakeScriptsExecutableResult,
|
|
557
|
+
isServiceMeProjectScaffoldPruneResult,
|
|
558
|
+
isServicemeErrorCode,
|
|
559
|
+
isServicemeErrorDetails,
|
|
560
|
+
isSystemHelloResult,
|
|
561
|
+
isSystemPingResult,
|
|
562
|
+
isSystemShutdownResult,
|
|
563
|
+
isToolCheckResult,
|
|
564
|
+
normalizeServicemeError
|
|
565
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|