cli-confirm-protocol 7.0.31 → 7.0.33
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/broker.mjs +53 -2
- package/installer.mjs +15 -5
- package/package.json +1 -1
- package/skill/SKILL.md +1 -1
- package/skill/skill.json +1 -1
package/broker.mjs
CHANGED
|
@@ -24,6 +24,20 @@ const VALIDATION_STATES = new Set(['passed', 'failed', 'incomplete'])
|
|
|
24
24
|
const EVALUATION_SCHEMA = 'skill-automatic-evaluation/1.0'
|
|
25
25
|
const IDENTIFIER_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/
|
|
26
26
|
const REQUEST_SCHEMA_PATTERN = /^([A-Za-z0-9.-]+\.skill)\.request\/([0-9]+\.[0-9]+)$/
|
|
27
|
+
const TRANSPORT_ERROR_CODE_PATTERN = /^[A-Z][A-Z0-9_]{1,63}$/
|
|
28
|
+
const NETWORK_TRANSPORT_ERROR = 'NETWORK_TRANSPORT'
|
|
29
|
+
const SKILL_INVOCATION_ERROR = 'SKILL_INVOCATION_FAILED'
|
|
30
|
+
|
|
31
|
+
class OfficialSkillInvocationError extends Error {
|
|
32
|
+
constructor(context, operation, transportCode) {
|
|
33
|
+
super(`${context.displayName} ${operation} invocation failed: network transport ${transportCode}`)
|
|
34
|
+
this.name = 'OfficialSkillInvocationError'
|
|
35
|
+
this.code = NETWORK_TRANSPORT_ERROR
|
|
36
|
+
this.operation = operation
|
|
37
|
+
this.retryable = false
|
|
38
|
+
this.transportCode = transportCode
|
|
39
|
+
}
|
|
40
|
+
}
|
|
27
41
|
|
|
28
42
|
function asObject(value, label) {
|
|
29
43
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
@@ -222,6 +236,43 @@ function invocationRequest(context, operation, input) {
|
|
|
222
236
|
}
|
|
223
237
|
}
|
|
224
238
|
|
|
239
|
+
export function transportFailureCode(error) {
|
|
240
|
+
const inspected = new Set()
|
|
241
|
+
let candidate = error
|
|
242
|
+
while (candidate && typeof candidate === 'object' && !inspected.has(candidate)) {
|
|
243
|
+
inspected.add(candidate)
|
|
244
|
+
const code = typeof candidate.code === 'string' ? candidate.code.trim() : ''
|
|
245
|
+
if (TRANSPORT_ERROR_CODE_PATTERN.test(code)) return code
|
|
246
|
+
const name = typeof candidate.name === 'string' ? candidate.name.trim() : ''
|
|
247
|
+
if (name === 'AbortError' || name === 'TimeoutError') return name
|
|
248
|
+
candidate = candidate.cause
|
|
249
|
+
}
|
|
250
|
+
return 'UNKNOWN_TRANSPORT_ERROR'
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function officialSkillFailureResponse(error) {
|
|
254
|
+
if (error instanceof OfficialSkillInvocationError) {
|
|
255
|
+
return {
|
|
256
|
+
ok: false,
|
|
257
|
+
error: {
|
|
258
|
+
code: error.code,
|
|
259
|
+
message: error.message,
|
|
260
|
+
operation: error.operation,
|
|
261
|
+
retryable: error.retryable,
|
|
262
|
+
transportCode: error.transportCode,
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
ok: false,
|
|
268
|
+
error: {
|
|
269
|
+
code: SKILL_INVOCATION_ERROR,
|
|
270
|
+
message: error instanceof Error ? error.message : 'Skill invocation failed',
|
|
271
|
+
retryable: false,
|
|
272
|
+
},
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
225
276
|
export async function invokeOfficialSkill(context, operation, input, dependencies) {
|
|
226
277
|
const environment = asObject(dependencies.environment, 'broker environment')
|
|
227
278
|
if (typeof dependencies.request !== 'function') {
|
|
@@ -237,8 +288,8 @@ export async function invokeOfficialSkill(context, operation, input, dependencie
|
|
|
237
288
|
body: JSON.stringify({ input: requestEnvelope }),
|
|
238
289
|
signal: AbortSignal.timeout(CALL_TIMEOUT_MS),
|
|
239
290
|
})
|
|
240
|
-
} catch {
|
|
241
|
-
throw new
|
|
291
|
+
} catch (error) {
|
|
292
|
+
throw new OfficialSkillInvocationError(context, operation, transportFailureCode(error))
|
|
242
293
|
}
|
|
243
294
|
const payload = await responsePayload(response, `${context.displayName} ${operation} response`)
|
|
244
295
|
if (!response.ok || payload.ok !== true) {
|
package/installer.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
brokerCommandInput,
|
|
14
14
|
invokeCommandInput,
|
|
15
15
|
invokeOfficialSkill,
|
|
16
|
+
officialSkillFailureResponse,
|
|
16
17
|
} from './broker.mjs'
|
|
17
18
|
|
|
18
19
|
export {
|
|
@@ -25,6 +26,7 @@ export {
|
|
|
25
26
|
callOfficialSkill,
|
|
26
27
|
invokeCommandInput,
|
|
27
28
|
invokeOfficialSkill,
|
|
29
|
+
officialSkillFailureResponse,
|
|
28
30
|
} from './broker.mjs'
|
|
29
31
|
|
|
30
32
|
const INSTALL_META = 'install-meta.json'
|
|
@@ -184,11 +186,19 @@ async function readBrokerSource(input) {
|
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
async function runBrokerInvocation(context, commandInput) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
try {
|
|
190
|
+
const invocation = await invokeOfficialSkill(
|
|
191
|
+
context, commandInput.operation, commandInput.input, brokerDependencies(),
|
|
192
|
+
)
|
|
193
|
+
console.log(JSON.stringify(invocation))
|
|
194
|
+
return invocation
|
|
195
|
+
} catch (error) {
|
|
196
|
+
const response = officialSkillFailureResponse(error)
|
|
197
|
+
console.log(JSON.stringify({ response }))
|
|
198
|
+
console.error(response.error.message)
|
|
199
|
+
process.exitCode = 1
|
|
200
|
+
return null
|
|
201
|
+
}
|
|
192
202
|
}
|
|
193
203
|
|
|
194
204
|
export async function runIntakeHandshake(context, spec) {
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED