@sjawhar/claude-envoy 5.12.0 → 5.12.1
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/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/README.md +6 -3
- package/bin/envoy-send.ts +13 -4
- package/dist/dispatch.js +39 -5
- package/dist/envoy-channel.js +71 -6
- package/package.json +1 -1
- package/src/envoy-channel-server.ts +8 -0
- package/src/envoy-client.ts +9 -4
package/.omp-plugin/plugin.json
CHANGED
package/README.md
CHANGED
|
@@ -203,9 +203,12 @@ message from Dispatch's Agents page as that person's own turn.
|
|
|
203
203
|
different message under the same key, and where its `ENVOY_URL` is not a plain http(s) URL (one
|
|
204
204
|
with user info of any length, say) the URL is never printed; either way only the key is printed,
|
|
205
205
|
with how to resend the original. A resend under a key exits 75 on any failure, since the send
|
|
206
|
-
before it may have arrived.
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
before it may have arrived. A send whose idempotency key another sender's message already holds
|
|
207
|
+
stored nothing: it prints `Claude Envoy send not delivered: …`, naming that message's event id,
|
|
208
|
+
and exits 1; run again without the key, it goes under a new one. Any other refusal, one for the
|
|
209
|
+
sender's rate among them, prints the listener's own sentence after `Claude Envoy send failed: `,
|
|
210
|
+
exits 1 and is not sent again; so does a listener that refused the connection or whose name did
|
|
211
|
+
not resolve.
|
|
209
212
|
|
|
210
213
|
## What a delivered line carries
|
|
211
214
|
|
package/bin/envoy-send.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { holdUrlUserinfo, scrub, scrubProcessStreams } from "@legion/contracts/h
|
|
|
3
3
|
import { URL_NOT_PRINTED } from "@legion/contracts/log-text"
|
|
4
4
|
import { messageFor } from "@legion/envoy-client/errors"
|
|
5
5
|
import { sessionConfigFile, sessionEnvoySettings } from "@legion/envoy-client/session-settings"
|
|
6
|
+
import { keyTakenText } from "@legion/envoy-client/tool-contract"
|
|
6
7
|
import { EnvoySendUnconfirmedError } from "@legion/envoy-client/transport"
|
|
7
8
|
import { configuredSessionId } from "../src/claude-session"
|
|
8
9
|
import { sendEnvoyMessage } from "../src/envoy-client"
|
|
@@ -116,10 +117,18 @@ try {
|
|
|
116
117
|
...(send.idempotencyKey === undefined ? {} : { idempotencyKey: send.idempotencyKey }),
|
|
117
118
|
sourceSession: session ?? "",
|
|
118
119
|
})
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
if (sent.keyTaken !== undefined) {
|
|
121
|
+
// Another sender's message holds the key, so the listener stored nothing for this send: it
|
|
122
|
+
// was not delivered, and it is no send that may have arrived. A run without the key mints a
|
|
123
|
+
// new one, which delivers it.
|
|
124
|
+
process.stderr.write(`Claude Envoy send ${keyTakenText(sent, "envoy_send")}\n`)
|
|
125
|
+
process.exitCode = 1
|
|
126
|
+
} else {
|
|
127
|
+
process.stdout.write(`Sent Envoy message to ${send.targetSession}.\n`)
|
|
128
|
+
// Stored, so it exits 0; but a send that went without its credential says why, once.
|
|
129
|
+
if (sent.withoutCredential !== undefined)
|
|
130
|
+
process.stderr.write(wentWithout(sent.withoutCredential))
|
|
131
|
+
}
|
|
123
132
|
} catch (error) {
|
|
124
133
|
// A send that may have arrived is not a failure, and nor is any failure of a resend that names
|
|
125
134
|
// a key: the send under that key before it may have arrived, so a refusal now says nothing of
|
package/dist/dispatch.js
CHANGED
|
@@ -34949,6 +34949,29 @@ var PublishResponseSchema = EnvelopeResponseSchema.extend({
|
|
|
34949
34949
|
kept_reason: _enum2(["unclaimed", "holder_lapsed"]).optional(),
|
|
34950
34950
|
kept_until: number2().int().optional()
|
|
34951
34951
|
});
|
|
34952
|
+
var READS_HEADER = "Envoy-Reads";
|
|
34953
|
+
var READS_KEY_TAKEN = "key-taken";
|
|
34954
|
+
var KeyTakenWireSchema = object({
|
|
34955
|
+
event_id: string2().min(1),
|
|
34956
|
+
topic: string2(),
|
|
34957
|
+
dedupe_key: string2(),
|
|
34958
|
+
issued_at: number2().int(),
|
|
34959
|
+
duplicate: literal(true),
|
|
34960
|
+
payload_summary: literal("").optional()
|
|
34961
|
+
});
|
|
34962
|
+
function keyTakenOf(raw) {
|
|
34963
|
+
const taken = KeyTakenWireSchema.safeParse(raw);
|
|
34964
|
+
if (!taken.success)
|
|
34965
|
+
return;
|
|
34966
|
+
return {
|
|
34967
|
+
keyTaken: {
|
|
34968
|
+
eventId: taken.data.event_id,
|
|
34969
|
+
topic: taken.data.topic,
|
|
34970
|
+
issuedAt: taken.data.issued_at
|
|
34971
|
+
},
|
|
34972
|
+
delivered: false
|
|
34973
|
+
};
|
|
34974
|
+
}
|
|
34952
34975
|
var DeliveryRefusalSchema = object({
|
|
34953
34976
|
mode: string2(),
|
|
34954
34977
|
reason: string2().optional()
|
|
@@ -35196,7 +35219,10 @@ function createEnvoyClient(config) {
|
|
|
35196
35219
|
};
|
|
35197
35220
|
const post = (path, body, options) => request(path, {
|
|
35198
35221
|
method: "POST",
|
|
35199
|
-
headers: {
|
|
35222
|
+
headers: {
|
|
35223
|
+
"Content-Type": "application/json",
|
|
35224
|
+
...options?.readsKeyTaken === true ? { [READS_HEADER]: READS_KEY_TAKEN } : {}
|
|
35225
|
+
},
|
|
35200
35226
|
body: JSON.stringify(body)
|
|
35201
35227
|
}, options);
|
|
35202
35228
|
const subscribeBody = (input) => ({
|
|
@@ -35249,9 +35275,13 @@ function createEnvoyClient(config) {
|
|
|
35249
35275
|
onNotSent: () => {
|
|
35250
35276
|
notSent = true;
|
|
35251
35277
|
},
|
|
35252
|
-
...input.sourceSessionID === undefined || input.sourceSessionID === "" ? {} : { actingSession: input.sourceSessionID }
|
|
35278
|
+
...input.sourceSessionID === undefined || input.sourceSessionID === "" ? {} : { actingSession: input.sourceSessionID, readsKeyTaken: true }
|
|
35253
35279
|
});
|
|
35254
|
-
|
|
35280
|
+
const raw = answerJson(answer, "POST", "/v1/messages/send");
|
|
35281
|
+
const taken = keyTakenOf(raw);
|
|
35282
|
+
if (taken !== undefined)
|
|
35283
|
+
return taken;
|
|
35284
|
+
response = EnvelopeResponseSchema.parse(raw);
|
|
35255
35285
|
} catch (error) {
|
|
35256
35286
|
const refused = notSent || error instanceof EnvoyApiError && error.details.status < 500;
|
|
35257
35287
|
if (refused && !unanswered)
|
|
@@ -35270,7 +35300,7 @@ function createEnvoyClient(config) {
|
|
|
35270
35300
|
},
|
|
35271
35301
|
publish: async (input) => {
|
|
35272
35302
|
const idempotencyKey = input.idempotencyKey ?? crypto.randomUUID();
|
|
35273
|
-
const
|
|
35303
|
+
const raw = answerJson(await post("/v1/messages/publish", {
|
|
35274
35304
|
source: input.source ?? "agent",
|
|
35275
35305
|
...sourceSession(input.sourceSessionID),
|
|
35276
35306
|
topic: input.topic,
|
|
@@ -35279,7 +35309,11 @@ function createEnvoyClient(config) {
|
|
|
35279
35309
|
idempotency_key: idempotencyKey,
|
|
35280
35310
|
...messageMetadata(input),
|
|
35281
35311
|
...input.keep === undefined ? {} : { keep: input.keep }
|
|
35282
|
-
}, input.sourceSessionID === undefined || input.sourceSessionID === "" ? {} : { actingSession: input.sourceSessionID }), "POST", "/v1/messages/publish")
|
|
35312
|
+
}, input.sourceSessionID === undefined || input.sourceSessionID === "" ? {} : { actingSession: input.sourceSessionID, readsKeyTaken: true }), "POST", "/v1/messages/publish");
|
|
35313
|
+
const taken = keyTakenOf(raw);
|
|
35314
|
+
if (taken !== undefined)
|
|
35315
|
+
return taken;
|
|
35316
|
+
const response = PublishResponseSchema.parse(raw);
|
|
35283
35317
|
return {
|
|
35284
35318
|
envelope: response,
|
|
35285
35319
|
...response.holder === undefined ? {} : { holder: response.holder },
|
package/dist/envoy-channel.js
CHANGED
|
@@ -56837,6 +56837,29 @@ var PublishResponseSchema = EnvelopeResponseSchema.extend({
|
|
|
56837
56837
|
kept_reason: _enum2(["unclaimed", "holder_lapsed"]).optional(),
|
|
56838
56838
|
kept_until: number2().int().optional()
|
|
56839
56839
|
});
|
|
56840
|
+
var READS_HEADER = "Envoy-Reads";
|
|
56841
|
+
var READS_KEY_TAKEN = "key-taken";
|
|
56842
|
+
var KeyTakenWireSchema = object({
|
|
56843
|
+
event_id: string2().min(1),
|
|
56844
|
+
topic: string2(),
|
|
56845
|
+
dedupe_key: string2(),
|
|
56846
|
+
issued_at: number2().int(),
|
|
56847
|
+
duplicate: literal(true),
|
|
56848
|
+
payload_summary: literal("").optional()
|
|
56849
|
+
});
|
|
56850
|
+
function keyTakenOf(raw) {
|
|
56851
|
+
const taken = KeyTakenWireSchema.safeParse(raw);
|
|
56852
|
+
if (!taken.success)
|
|
56853
|
+
return;
|
|
56854
|
+
return {
|
|
56855
|
+
keyTaken: {
|
|
56856
|
+
eventId: taken.data.event_id,
|
|
56857
|
+
topic: taken.data.topic,
|
|
56858
|
+
issuedAt: taken.data.issued_at
|
|
56859
|
+
},
|
|
56860
|
+
delivered: false
|
|
56861
|
+
};
|
|
56862
|
+
}
|
|
56840
56863
|
var DeliveryRefusalSchema = object({
|
|
56841
56864
|
mode: string2(),
|
|
56842
56865
|
reason: string2().optional()
|
|
@@ -57084,7 +57107,10 @@ function createEnvoyClient(config) {
|
|
|
57084
57107
|
};
|
|
57085
57108
|
const post = (path, body, options) => request(path, {
|
|
57086
57109
|
method: "POST",
|
|
57087
|
-
headers: {
|
|
57110
|
+
headers: {
|
|
57111
|
+
"Content-Type": "application/json",
|
|
57112
|
+
...options?.readsKeyTaken === true ? { [READS_HEADER]: READS_KEY_TAKEN } : {}
|
|
57113
|
+
},
|
|
57088
57114
|
body: JSON.stringify(body)
|
|
57089
57115
|
}, options);
|
|
57090
57116
|
const subscribeBody = (input) => ({
|
|
@@ -57137,9 +57163,13 @@ function createEnvoyClient(config) {
|
|
|
57137
57163
|
onNotSent: () => {
|
|
57138
57164
|
notSent = true;
|
|
57139
57165
|
},
|
|
57140
|
-
...input.sourceSessionID === undefined || input.sourceSessionID === "" ? {} : { actingSession: input.sourceSessionID }
|
|
57166
|
+
...input.sourceSessionID === undefined || input.sourceSessionID === "" ? {} : { actingSession: input.sourceSessionID, readsKeyTaken: true }
|
|
57141
57167
|
});
|
|
57142
|
-
|
|
57168
|
+
const raw = answerJson(answer, "POST", "/v1/messages/send");
|
|
57169
|
+
const taken = keyTakenOf(raw);
|
|
57170
|
+
if (taken !== undefined)
|
|
57171
|
+
return taken;
|
|
57172
|
+
response = EnvelopeResponseSchema.parse(raw);
|
|
57143
57173
|
} catch (error) {
|
|
57144
57174
|
const refused = notSent || error instanceof EnvoyApiError && error.details.status < 500;
|
|
57145
57175
|
if (refused && !unanswered)
|
|
@@ -57158,7 +57188,7 @@ function createEnvoyClient(config) {
|
|
|
57158
57188
|
},
|
|
57159
57189
|
publish: async (input) => {
|
|
57160
57190
|
const idempotencyKey = input.idempotencyKey ?? crypto.randomUUID();
|
|
57161
|
-
const
|
|
57191
|
+
const raw = answerJson(await post("/v1/messages/publish", {
|
|
57162
57192
|
source: input.source ?? "agent",
|
|
57163
57193
|
...sourceSession(input.sourceSessionID),
|
|
57164
57194
|
topic: input.topic,
|
|
@@ -57167,7 +57197,11 @@ function createEnvoyClient(config) {
|
|
|
57167
57197
|
idempotency_key: idempotencyKey,
|
|
57168
57198
|
...messageMetadata(input),
|
|
57169
57199
|
...input.keep === undefined ? {} : { keep: input.keep }
|
|
57170
|
-
}, input.sourceSessionID === undefined || input.sourceSessionID === "" ? {} : { actingSession: input.sourceSessionID }), "POST", "/v1/messages/publish")
|
|
57200
|
+
}, input.sourceSessionID === undefined || input.sourceSessionID === "" ? {} : { actingSession: input.sourceSessionID, readsKeyTaken: true }), "POST", "/v1/messages/publish");
|
|
57201
|
+
const taken = keyTakenOf(raw);
|
|
57202
|
+
if (taken !== undefined)
|
|
57203
|
+
return taken;
|
|
57204
|
+
const response = PublishResponseSchema.parse(raw);
|
|
57171
57205
|
return {
|
|
57172
57206
|
envelope: response,
|
|
57173
57207
|
...response.holder === undefined ? {} : { holder: response.holder },
|
|
@@ -61911,6 +61945,21 @@ function sendConfirmationText(result) {
|
|
|
61911
61945
|
const state = result.recipientState === "unresponsive" ? `unresponsive${since}, so it is stored until that session answers; ${UNRESPONSIVE_RULE}` : result.recipientState;
|
|
61912
61946
|
return `sent ${result.envelope.event_id} to ${result.recipient} (${state})${result.confirmed ? "" : " (recipient unconfirmed by listener)"}`;
|
|
61913
61947
|
}
|
|
61948
|
+
var KEY_TAKEN_AGAIN = {
|
|
61949
|
+
envoy_send: "send it again without an idempotency_key; Envoy gives it a new one",
|
|
61950
|
+
envoy_publish: "publish it again; Envoy gives every publish a new idempotency_key"
|
|
61951
|
+
};
|
|
61952
|
+
function keyTakenText(result, tool) {
|
|
61953
|
+
return `not delivered: another sender's message (${result.keyTaken.eventId}) already holds this idempotency_key, so Envoy stored nothing for you; ${KEY_TAKEN_AGAIN[tool]}`;
|
|
61954
|
+
}
|
|
61955
|
+
function keyTakenDetails(result) {
|
|
61956
|
+
return {
|
|
61957
|
+
event_id: result.keyTaken.eventId,
|
|
61958
|
+
topic: result.keyTaken.topic,
|
|
61959
|
+
delivered: false,
|
|
61960
|
+
key_taken: true
|
|
61961
|
+
};
|
|
61962
|
+
}
|
|
61914
61963
|
function publishConfirmationText(result, options) {
|
|
61915
61964
|
const published = `published ${result.envelope.event_id}`;
|
|
61916
61965
|
if (result.recipients === 0) {
|
|
@@ -62150,7 +62199,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
|
|
|
62150
62199
|
|
|
62151
62200
|
// package.json
|
|
62152
62201
|
var name2 = "@sjawhar/claude-envoy";
|
|
62153
|
-
var version2 = "5.12.
|
|
62202
|
+
var version2 = "5.12.1";
|
|
62154
62203
|
var legion = {
|
|
62155
62204
|
daemonApiVersion: 217
|
|
62156
62205
|
};
|
|
@@ -65191,6 +65240,16 @@ function createPhaseReminder(deps) {
|
|
|
65191
65240
|
});
|
|
65192
65241
|
if (reportKey !== key)
|
|
65193
65242
|
return;
|
|
65243
|
+
if ("keyTaken" in answer) {
|
|
65244
|
+
reportKey = undefined;
|
|
65245
|
+
writeEntry();
|
|
65246
|
+
deps.log.warn("legion: another sender's message holds the architect notice's key; telling it again later", {
|
|
65247
|
+
issue: claim.issue,
|
|
65248
|
+
reminders,
|
|
65249
|
+
event_id: answer.keyTaken.eventId
|
|
65250
|
+
});
|
|
65251
|
+
return;
|
|
65252
|
+
}
|
|
65194
65253
|
if (answer.kept === true) {
|
|
65195
65254
|
if (answer.keptUntil === undefined) {
|
|
65196
65255
|
reportKey = undefined;
|
|
@@ -68577,6 +68636,9 @@ async function executeEnvoyTool(runtime, name, input) {
|
|
|
68577
68636
|
...args.idempotency_key === undefined ? {} : { idempotencyKey: args.idempotency_key },
|
|
68578
68637
|
...toMessageMetadata(args)
|
|
68579
68638
|
});
|
|
68639
|
+
if (result.keyTaken !== undefined) {
|
|
68640
|
+
return { message: keyTakenText(result, "envoy_send"), ...keyTakenDetails(result) };
|
|
68641
|
+
}
|
|
68580
68642
|
return {
|
|
68581
68643
|
message: sendConfirmationText(result),
|
|
68582
68644
|
event_id: result.envelope.event_id,
|
|
@@ -68596,6 +68658,9 @@ async function executeEnvoyTool(runtime, name, input) {
|
|
|
68596
68658
|
message: args.message,
|
|
68597
68659
|
...toMessageMetadata(args)
|
|
68598
68660
|
});
|
|
68661
|
+
if (result.keyTaken !== undefined) {
|
|
68662
|
+
return { message: keyTakenText(result, "envoy_publish"), ...keyTakenDetails(result) };
|
|
68663
|
+
}
|
|
68599
68664
|
return {
|
|
68600
68665
|
message: publishConfirmationText(result, { senderNamed: true }),
|
|
68601
68666
|
event_id: result.envelope.event_id,
|
package/package.json
CHANGED
|
@@ -64,6 +64,8 @@ import {
|
|
|
64
64
|
import {
|
|
65
65
|
EnvoyToolOperation,
|
|
66
66
|
envoyToolSpecs,
|
|
67
|
+
keyTakenDetails,
|
|
68
|
+
keyTakenText,
|
|
67
69
|
publishConfirmationText,
|
|
68
70
|
publishResultDetails,
|
|
69
71
|
sendConfirmationText,
|
|
@@ -2325,6 +2327,9 @@ export async function executeEnvoyTool(
|
|
|
2325
2327
|
...(args.idempotency_key === undefined ? {} : { idempotencyKey: args.idempotency_key }),
|
|
2326
2328
|
...toMessageMetadata(args),
|
|
2327
2329
|
})
|
|
2330
|
+
if (result.keyTaken !== undefined) {
|
|
2331
|
+
return { message: keyTakenText(result, "envoy_send"), ...keyTakenDetails(result) }
|
|
2332
|
+
}
|
|
2328
2333
|
return {
|
|
2329
2334
|
message: sendConfirmationText(result),
|
|
2330
2335
|
event_id: result.envelope.event_id,
|
|
@@ -2349,6 +2354,9 @@ export async function executeEnvoyTool(
|
|
|
2349
2354
|
// plugin uses (`publishConfirmationText`). This server always names its own session as the
|
|
2350
2355
|
// source, so the listener sends that session a message for a kept copy no session took,
|
|
2351
2356
|
// unless it drops the copy more than an hour late, and the line says so.
|
|
2357
|
+
if (result.keyTaken !== undefined) {
|
|
2358
|
+
return { message: keyTakenText(result, "envoy_publish"), ...keyTakenDetails(result) }
|
|
2359
|
+
}
|
|
2352
2360
|
return {
|
|
2353
2361
|
message: publishConfirmationText(result, { senderNamed: true }),
|
|
2354
2362
|
event_id: result.envelope.event_id,
|
package/src/envoy-client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RequestCredential } from "@legion/envoy-client/bearer"
|
|
2
|
-
import { createEnvoyClient } from "@legion/envoy-client/transport"
|
|
2
|
+
import { createEnvoyClient, type KeyTakenResult } from "@legion/envoy-client/transport"
|
|
3
3
|
|
|
4
4
|
export type SendEnvoyMessageOptions = {
|
|
5
5
|
readonly baseUrl: string
|
|
@@ -27,6 +27,8 @@ export type SentEnvoyMessage = {
|
|
|
27
27
|
* went without included, and where the send was handed none to carry.
|
|
28
28
|
*/
|
|
29
29
|
readonly withoutCredential: unknown
|
|
30
|
+
/** Never set on a stored send: see {@link KeyTakenResult}. */
|
|
31
|
+
readonly keyTaken?: undefined
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
/**
|
|
@@ -86,11 +88,13 @@ function recorded(credential: RequestCredential): {
|
|
|
86
88
|
*
|
|
87
89
|
* A stored send answers what it went without (`SentEnvoyMessage`), so the command can say so: a
|
|
88
90
|
* sign-in revoked for good is stored without the credential by a listener that asks for none, and
|
|
89
|
-
* nothing else would tell the person.
|
|
91
|
+
* nothing else would tell the person. A send whose idempotency key another sender's message
|
|
92
|
+
* already holds stored nothing, and answers that (`KeyTakenResult`), naming that message's event
|
|
93
|
+
* id: the message was not delivered, and a send under a new key delivers it.
|
|
90
94
|
*/
|
|
91
95
|
export async function sendEnvoyMessage(
|
|
92
96
|
options: SendEnvoyMessageOptions,
|
|
93
|
-
): Promise<SentEnvoyMessage> {
|
|
97
|
+
): Promise<SentEnvoyMessage | KeyTakenResult> {
|
|
94
98
|
const kept = options.credential === undefined ? undefined : recorded(options.credential)
|
|
95
99
|
const client = createEnvoyClient({
|
|
96
100
|
baseUrl: options.baseUrl,
|
|
@@ -101,11 +105,12 @@ export async function sendEnvoyMessage(
|
|
|
101
105
|
// session's sending limit; a shell that names no session sends a blank one, which the transport
|
|
102
106
|
// leaves off the wire. A refusal is an `EnvoyApiError` whose message is the listener's own
|
|
103
107
|
// sentence, which `envoy-send` prints.
|
|
104
|
-
await client.send({
|
|
108
|
+
const result = await client.send({
|
|
105
109
|
sourceSessionID: options.sourceSession ?? "",
|
|
106
110
|
targetSessionID: options.targetSession,
|
|
107
111
|
message: options.message,
|
|
108
112
|
...(options.idempotencyKey === undefined ? {} : { idempotencyKey: options.idempotencyKey }),
|
|
109
113
|
})
|
|
114
|
+
if (result.keyTaken !== undefined) return result
|
|
110
115
|
return { withoutCredential: kept?.lastFailure() }
|
|
111
116
|
}
|