@masons/agent-network 0.6.3 → 0.6.5
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/_vendor/trace-context.d.ts +19 -0
- package/dist/_vendor/trace-context.d.ts.map +1 -0
- package/dist/_vendor/trace-context.js +66 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js +19 -11
- package/dist/connector-client.d.ts +3 -0
- package/dist/connector-client.d.ts.map +1 -1
- package/dist/connector-client.js +47 -7
- package/dist/conversation-manager.d.ts.map +1 -1
- package/dist/conversation-manager.js +10 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/platform-client.d.ts +5 -0
- package/dist/platform-client.d.ts.map +1 -1
- package/dist/platform-client.js +58 -6
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +27 -1
- package/dist/trace-metadata.d.ts +15 -0
- package/dist/trace-metadata.d.ts.map +1 -0
- package/dist/trace-metadata.js +36 -0
- package/dist/types.d.ts +16 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +19 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface TraceContext {
|
|
2
|
+
readonly traceId: string;
|
|
3
|
+
readonly spanId: string;
|
|
4
|
+
readonly flags: string;
|
|
5
|
+
}
|
|
6
|
+
export type TraceparentReason = "present" | "missing" | "invalid";
|
|
7
|
+
export interface EnsuredTraceContext {
|
|
8
|
+
readonly traceparent: string;
|
|
9
|
+
readonly traceId: string;
|
|
10
|
+
readonly degraded: boolean;
|
|
11
|
+
readonly reason: TraceparentReason;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseTraceparent(value: string | undefined | null): TraceContext | null;
|
|
14
|
+
export declare function formatTraceparent(ctx: TraceContext): string;
|
|
15
|
+
export declare function mintTraceparent(): string;
|
|
16
|
+
export declare function extractTraceId(value: string | undefined | null): string | null;
|
|
17
|
+
export declare function ensureTraceparent(value: string | undefined | null): EnsuredTraceContext;
|
|
18
|
+
export declare function childTraceparent(value: string | undefined | null): string | null;
|
|
19
|
+
//# sourceMappingURL=trace-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-context.d.ts","sourceRoot":"","sources":["../../src/_vendor/trace-context.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,YAAY;IAE3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAGD,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAElE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAM3B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;CACpC;AAqBD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC/B,YAAY,GAAG,IAAI,CAQrB;AAGD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAE3D;AAGD,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAGD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC/B,MAAM,GAAG,IAAI,CAEf;AAQD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC/B,mBAAmB,CAcrB;AAOD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC/B,MAAM,GAAG,IAAI,CAIf"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const TRACE_ID_HEX = 32;
|
|
2
|
+
const SPAN_ID_HEX = 16;
|
|
3
|
+
const VERSION = "00";
|
|
4
|
+
const SAMPLED_FLAGS = "01";
|
|
5
|
+
const ZERO_TRACE_ID = "0".repeat(TRACE_ID_HEX);
|
|
6
|
+
const ZERO_SPAN_ID = "0".repeat(SPAN_ID_HEX);
|
|
7
|
+
const TRACEPARENT_RE = /^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$/;
|
|
8
|
+
function randomHex(hexChars) {
|
|
9
|
+
const bytes = new Uint8Array(hexChars / 2);
|
|
10
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
11
|
+
let out = "";
|
|
12
|
+
for (const byte of bytes) {
|
|
13
|
+
out += byte.toString(16).padStart(2, "0");
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
function mintContext() {
|
|
18
|
+
return {
|
|
19
|
+
traceId: randomHex(TRACE_ID_HEX),
|
|
20
|
+
spanId: randomHex(SPAN_ID_HEX),
|
|
21
|
+
flags: SAMPLED_FLAGS,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function parseTraceparent(value) {
|
|
25
|
+
if (typeof value !== "string")
|
|
26
|
+
return null;
|
|
27
|
+
const normalized = value.trim().toLowerCase();
|
|
28
|
+
if (!TRACEPARENT_RE.test(normalized))
|
|
29
|
+
return null;
|
|
30
|
+
const [, traceId, spanId, flags] = normalized.split("-");
|
|
31
|
+
if (!traceId || !spanId || !flags)
|
|
32
|
+
return null;
|
|
33
|
+
if (traceId === ZERO_TRACE_ID || spanId === ZERO_SPAN_ID)
|
|
34
|
+
return null;
|
|
35
|
+
return { traceId, spanId, flags };
|
|
36
|
+
}
|
|
37
|
+
export function formatTraceparent(ctx) {
|
|
38
|
+
return `${VERSION}-${ctx.traceId}-${ctx.spanId}-${ctx.flags}`;
|
|
39
|
+
}
|
|
40
|
+
export function mintTraceparent() {
|
|
41
|
+
return formatTraceparent(mintContext());
|
|
42
|
+
}
|
|
43
|
+
export function extractTraceId(value) {
|
|
44
|
+
return parseTraceparent(value)?.traceId ?? null;
|
|
45
|
+
}
|
|
46
|
+
export function ensureTraceparent(value) {
|
|
47
|
+
const parsed = parseTraceparent(value);
|
|
48
|
+
const ctx = parsed ?? mintContext();
|
|
49
|
+
const reason = parsed
|
|
50
|
+
? "present"
|
|
51
|
+
: value == null || (typeof value === "string" && value.trim() === "")
|
|
52
|
+
? "missing"
|
|
53
|
+
: "invalid";
|
|
54
|
+
return {
|
|
55
|
+
traceparent: formatTraceparent(ctx),
|
|
56
|
+
traceId: ctx.traceId,
|
|
57
|
+
degraded: parsed === null,
|
|
58
|
+
reason,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function childTraceparent(value) {
|
|
62
|
+
const parsed = parseTraceparent(value);
|
|
63
|
+
if (!parsed)
|
|
64
|
+
return null;
|
|
65
|
+
return `${VERSION}-${parsed.traceId}-${randomHex(SPAN_ID_HEX)}-${parsed.flags}`;
|
|
66
|
+
}
|
package/dist/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAyC9D,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,IAAI,CAEvD;AAOD,wBAAgB,2BAA2B,IAAI,OAAO,CAIrD;AAGD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAE/D;AAUD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,I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AW,CAAC;CAC1B;AA2DD,iBAAS,iCAAiC,CACxC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA6BzB;AAED,eAAO,MAAM,4CAA4C,0CACtB,CAAC;AAEpC,UAAU,qBAAqB,CAAC,CAAC,GAAG,OAAO;IACzC,YAAY,CAAC,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/D,WAAW,CAAC,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5D;AAED,UAAU,yBAAyB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,YAAY,EAAE,mBAAmB,CAAC;IAClC,MAAM,EAAE,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;IAClD,QAAQ,EAAE,sBAAsB,CAAC;IACjC,OAAO,EAAE,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;CACrD;AAyaD,eAAO,MAAM,mBAAmB,EAAE,yBA+NjC,CAAC"}
|
package/dist/channel.js
CHANGED
|
@@ -7,6 +7,7 @@ import { ConversationManager } from "./conversation-manager.js";
|
|
|
7
7
|
import { clearEnvironmentContext } from "./environment-context.js";
|
|
8
8
|
import { extractHandleFromAddress } from "./handle-utils.js";
|
|
9
9
|
import { clearOwnerState, isOwnerAddress, markOwnerAddress, setCurrentTurnIsOwner, setCurrentTurnOwnerSignal, } from "./owner-session-state.js";
|
|
10
|
+
import { createReplyTraceMetadata, ensureTraceMetadata, } from "./trace-metadata.js";
|
|
10
11
|
import { setCurrentTurnSender } from "./turn-context.js";
|
|
11
12
|
import { checkForUpdate } from "./update-check.js";
|
|
12
13
|
const dbg = createDebug("agent-network:channel");
|
|
@@ -113,24 +114,30 @@ function isDuplicate(from, content, sentAt) {
|
|
|
113
114
|
async function handleAddressedMessage(event, conversationManager, client, ctx) {
|
|
114
115
|
const fromAddress = event.from;
|
|
115
116
|
dbg("routing inbound message from=%s contentLength=%d", fromAddress, event.content.length);
|
|
117
|
+
const inboundTrace = ensureTraceMetadata(event.metadata);
|
|
118
|
+
const metadata = inboundTrace.metadata;
|
|
119
|
+
if (inboundTrace.degraded) {
|
|
120
|
+
dbg("trace context degraded inbound from=%s traceId=%s reason=%s spanName=receive", fromAddress, inboundTrace.traceId, inboundTrace.reason);
|
|
121
|
+
if (inboundTrace.reason === "invalid") {
|
|
122
|
+
console.warn(`[agent-network:channel] invalid traceparent from=${fromAddress} traceId=${inboundTrace.traceId} spanName=receive`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
116
125
|
if (isDuplicate(fromAddress, event.content, event.sentAt)) {
|
|
117
126
|
dbg("duplicate message suppressed from=%s sentAt=%s", fromAddress, event.sentAt);
|
|
118
127
|
return;
|
|
119
128
|
}
|
|
120
|
-
const inboundCorrelationId = typeof
|
|
121
|
-
?
|
|
122
|
-
: undefined;
|
|
123
|
-
const inboundMessageId = typeof event.metadata?.message_id === "string"
|
|
124
|
-
? event.metadata.message_id
|
|
129
|
+
const inboundCorrelationId = typeof metadata.correlation_id === "string"
|
|
130
|
+
? metadata.correlation_id
|
|
125
131
|
: undefined;
|
|
126
|
-
const
|
|
132
|
+
const inboundMessageId = typeof metadata.message_id === "string" ? metadata.message_id : undefined;
|
|
133
|
+
const nodeRef = tryProjectNodeRef(metadata);
|
|
127
134
|
if (nodeRef) {
|
|
128
135
|
setCurrentTurnIsOwner(false);
|
|
129
136
|
setCurrentTurnOwnerSignal(null);
|
|
130
137
|
dbg("Full Node sender: kind=%s mstpAddress=%s handle=%s", nodeRef.kind, nodeRef.mstpAddress, nodeRef.handle ?? "(absent)");
|
|
131
138
|
}
|
|
132
139
|
else {
|
|
133
|
-
if (
|
|
140
|
+
if (metadata.is_owner === true) {
|
|
134
141
|
markOwnerAddress(fromAddress);
|
|
135
142
|
if (!storedOwnerPassportAddress) {
|
|
136
143
|
storedOwnerPassportAddress = fromAddress;
|
|
@@ -145,10 +152,10 @@ async function handleAddressedMessage(event, conversationManager, client, ctx) {
|
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
setCurrentTurnIsOwner(isOwnerAddress(fromAddress));
|
|
148
|
-
if (
|
|
155
|
+
if (metadata.is_owner === true) {
|
|
149
156
|
setCurrentTurnOwnerSignal("owner");
|
|
150
157
|
}
|
|
151
|
-
else if (
|
|
158
|
+
else if (metadata.is_owner === false) {
|
|
152
159
|
setCurrentTurnOwnerSignal("non-owner");
|
|
153
160
|
}
|
|
154
161
|
else {
|
|
@@ -237,8 +244,9 @@ async function handleAddressedMessage(event, conversationManager, client, ctx) {
|
|
|
237
244
|
if (inboundMessageId !== undefined) {
|
|
238
245
|
replyMetadata.in_reply_to = inboundMessageId;
|
|
239
246
|
}
|
|
240
|
-
const
|
|
241
|
-
|
|
247
|
+
const replyTrace = createReplyTraceMetadata(metadata, replyMetadata);
|
|
248
|
+
const deliverResult = await conversationManager.send(senderId, text, replyTrace.metadata);
|
|
249
|
+
dbg("deliver reply senderId=%s status=%s contentLength=%d traceId=%s originalTraceId=%s spanName=send", senderId, deliverResult.status, text.length, replyTrace.traceId, replyTrace.originalTraceId ?? "(absent)");
|
|
242
250
|
},
|
|
243
251
|
onError: (err) => {
|
|
244
252
|
console.error(`[agent-network:${ctx.accountId}] dispatch error:`, err);
|
|
@@ -54,7 +54,10 @@ export declare class ConnectorClient extends EventEmitter {
|
|
|
54
54
|
private handleMessage;
|
|
55
55
|
private dispatchAddressed;
|
|
56
56
|
private handleAddressedMessage;
|
|
57
|
+
private handleDeliverySkip;
|
|
58
|
+
private adoptDeliveredFloor;
|
|
57
59
|
private acceptContiguous;
|
|
60
|
+
private drainPendingSeqMessagesFrom;
|
|
58
61
|
private rememberPayloadId;
|
|
59
62
|
private handleRegisterAck;
|
|
60
63
|
private handleSendAck;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector-client.d.ts","sourceRoot":"","sources":["../src/connector-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EAEL,KAAK,qBAAqB,EAI1B,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"connector-client.d.ts","sourceRoot":"","sources":["../src/connector-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EAEL,KAAK,qBAAqB,EAI1B,KAAK,oBAAoB,EAEzB,KAAK,mBAAmB,EAcxB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC1B,MAAM,YAAY,CAAC;AA2BpB,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;gBACT,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM;CAMvD;AAID,KAAK,qBAAqB,GAAG;IAC3B,gBAAgB,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACzD,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IACxC,gBAAgB,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACxD,eAAe,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACtD,gBAAgB,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACxD,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B,CAAC;AAIF,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC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AIjB;IAIF,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,iBAAiB;IAsBzB,OAAO,CAAC,SAAS;CAelB"}
|
package/dist/connector-client.js
CHANGED
|
@@ -3,7 +3,7 @@ import { EventEmitter } from "node:events";
|
|
|
3
3
|
import createDebug from "debug";
|
|
4
4
|
import WebSocket from "ws";
|
|
5
5
|
import { setEnvironmentContext } from "./environment-context.js";
|
|
6
|
-
import { CURRENT_PROTOCOL_VERSION, isAddressedMessage, isDeliveryCursor, isDeliveryPending, isDeliveryStatus, isRegisterAck, isSendAck, isStructuredError, REGISTER_ACK_TIMEOUT_MS, SEND_ACK_TIMEOUT_MS, } from "./types.js";
|
|
6
|
+
import { CURRENT_PROTOCOL_VERSION, isAddressedMessage, isDeliveryCursor, isDeliveryPending, isDeliverySkip, isDeliveryStatus, isRegisterAck, isSendAck, isStructuredError, REGISTER_ACK_TIMEOUT_MS, SEND_ACK_TIMEOUT_MS, } from "./types.js";
|
|
7
7
|
import { PLUGIN_VERSION } from "./version.js";
|
|
8
8
|
const dbg = createDebug("agent-network:connector");
|
|
9
9
|
const dbgMsg = createDebug("agent-network:connector:msg");
|
|
@@ -214,8 +214,12 @@ export class ConnectorClient extends EventEmitter {
|
|
|
214
214
|
if (isDeliveryCursor(parsed)) {
|
|
215
215
|
const floor = this.lastKnownSeq ?? 0;
|
|
216
216
|
dbg("DELIVERY_CURSOR deliverySeq=%d deliveredSeq=%s local=%d", parsed.deliverySeq, parsed.deliveredSeq ?? "none", floor);
|
|
217
|
-
if (parsed.
|
|
218
|
-
this.
|
|
217
|
+
if (parsed.deliveredSeq !== undefined && parsed.deliveredSeq > floor) {
|
|
218
|
+
this.adoptDeliveredFloor(parsed.deliveredSeq);
|
|
219
|
+
}
|
|
220
|
+
const reconciledFloor = this.lastKnownSeq ?? 0;
|
|
221
|
+
if (parsed.deliverySeq > reconciledFloor) {
|
|
222
|
+
this.requestGapFill(reconciledFloor);
|
|
219
223
|
}
|
|
220
224
|
else if (parsed.deliveredSeq !== undefined &&
|
|
221
225
|
this.lastKnownSeq !== undefined &&
|
|
@@ -224,6 +228,11 @@ export class ConnectorClient extends EventEmitter {
|
|
|
224
228
|
}
|
|
225
229
|
return;
|
|
226
230
|
}
|
|
231
|
+
if (isDeliverySkip(parsed)) {
|
|
232
|
+
dbg("DELIVERY_SKIP seq=%d reason=%s messageId=%s", parsed.seq, parsed.reason, parsed.messageId ?? "none");
|
|
233
|
+
this.handleDeliverySkip(parsed);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
227
236
|
if (isStructuredError(parsed)) {
|
|
228
237
|
dbg("ERROR code=%s message=%s", parsed.code, parsed.message);
|
|
229
238
|
this.handleStructuredError(parsed);
|
|
@@ -249,13 +258,45 @@ export class ConnectorClient extends EventEmitter {
|
|
|
249
258
|
}
|
|
250
259
|
this.acceptContiguous(message);
|
|
251
260
|
}
|
|
261
|
+
handleDeliverySkip(event) {
|
|
262
|
+
const floor = this.lastKnownSeq ?? 0;
|
|
263
|
+
if (event.seq <= floor)
|
|
264
|
+
return;
|
|
265
|
+
if (event.seq > floor + 1) {
|
|
266
|
+
this.requestGapFill(floor);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
this.lastKnownSeq = event.seq;
|
|
270
|
+
this.drainPendingSeqMessagesFrom(event.seq + 1);
|
|
271
|
+
this.ackDelivery(this.lastKnownSeq);
|
|
272
|
+
}
|
|
273
|
+
adoptDeliveredFloor(seq) {
|
|
274
|
+
if (!Number.isInteger(seq) || seq < 0)
|
|
275
|
+
return;
|
|
276
|
+
const floor = this.lastKnownSeq ?? 0;
|
|
277
|
+
if (seq <= floor)
|
|
278
|
+
return;
|
|
279
|
+
this.lastKnownSeq = seq;
|
|
280
|
+
for (const pendingSeq of [...this.pendingSeqMessages.keys()]) {
|
|
281
|
+
if (pendingSeq <= seq)
|
|
282
|
+
this.pendingSeqMessages.delete(pendingSeq);
|
|
283
|
+
}
|
|
284
|
+
this.drainPendingSeqMessagesFrom(seq + 1);
|
|
285
|
+
if (this.lastKnownSeq > seq) {
|
|
286
|
+
this.ackDelivery(this.lastKnownSeq);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
252
289
|
acceptContiguous(message) {
|
|
253
290
|
const seq = message.seq;
|
|
254
291
|
if (typeof seq !== "number")
|
|
255
292
|
return;
|
|
256
293
|
this.emit("message_received", message);
|
|
257
294
|
this.lastKnownSeq = seq;
|
|
258
|
-
|
|
295
|
+
this.drainPendingSeqMessagesFrom(seq + 1);
|
|
296
|
+
this.ackDelivery(this.lastKnownSeq);
|
|
297
|
+
}
|
|
298
|
+
drainPendingSeqMessagesFrom(startSeq) {
|
|
299
|
+
let next = startSeq;
|
|
259
300
|
while (this.pendingSeqMessages.has(next)) {
|
|
260
301
|
const pending = this.pendingSeqMessages.get(next);
|
|
261
302
|
this.pendingSeqMessages.delete(next);
|
|
@@ -265,7 +306,6 @@ export class ConnectorClient extends EventEmitter {
|
|
|
265
306
|
this.lastKnownSeq = next;
|
|
266
307
|
next++;
|
|
267
308
|
}
|
|
268
|
-
this.ackDelivery(next - 1);
|
|
269
309
|
}
|
|
270
310
|
rememberPayloadId(payloadId) {
|
|
271
311
|
if (this.seenPayloadIds.has(payloadId))
|
|
@@ -292,13 +332,13 @@ export class ConnectorClient extends EventEmitter {
|
|
|
292
332
|
}
|
|
293
333
|
setEnvironmentContext(ack.agent, ack.owner);
|
|
294
334
|
if (typeof ack.deliverySeq === "number" &&
|
|
295
|
-
|
|
335
|
+
this.lastKnownSeq === undefined) {
|
|
296
336
|
this.lastKnownSeq = ack.deliverySeq;
|
|
297
337
|
for (const seq of [...this.pendingSeqMessages.keys()]) {
|
|
298
338
|
if (seq <= ack.deliverySeq)
|
|
299
339
|
this.pendingSeqMessages.delete(seq);
|
|
300
340
|
}
|
|
301
|
-
dbg("delivery cursor
|
|
341
|
+
dbg("delivery cursor initialized from register ack: %d", ack.deliverySeq);
|
|
302
342
|
}
|
|
303
343
|
else if (typeof ack.deliverySeq === "number" &&
|
|
304
344
|
this.lastKnownSeq !== undefined &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-manager.d.ts","sourceRoot":"","sources":["../src/conversation-manager.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation-manager.d.ts","sourceRoot":"","sources":["../src/conversation-manager.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,uBAAuB,CAAC;AAU7E,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,OAAO,GAAG,QAAQ,CAAC;IAchC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,OAAO,GAAG,QAAQ,CAAC;CACjC;AA4BD,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IAGvC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAwC;gBAE1D,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM;IAuBpD,IAAI,CACR,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,UAAU,CAAC;IA6DtB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IASvD,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAkBxD,iBAAiB,IAAI,mBAAmB,EAAE;IAwB1C,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAiBzC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAyBzC,wBAAwB,IAAI,IAAI;IAgChC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAyBvC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAQtC,OAAO,CAAC,uBAAuB;IA0B/B,gBAAgB,IAAI,IAAI;CAGzB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import createDebug from "debug";
|
|
2
2
|
import { ConnectorError } from "./connector-client.js";
|
|
3
3
|
import { extractHandleFromAddress } from "./handle-utils.js";
|
|
4
|
+
import { ensureTraceMetadata } from "./trace-metadata.js";
|
|
4
5
|
const dbg = createDebug("agent-network:conversation-manager");
|
|
5
6
|
const ERROR_MESSAGES = {
|
|
6
7
|
ADDRESS_NOT_FOUND: "Cannot find agent '{to}'. Check the handle.",
|
|
@@ -26,10 +27,17 @@ export class ConversationManager {
|
|
|
26
27
|
}
|
|
27
28
|
async send(contact, content, metadata) {
|
|
28
29
|
const address = this.resolveAddress(contact);
|
|
30
|
+
const trace = ensureTraceMetadata(metadata);
|
|
31
|
+
if (trace.degraded) {
|
|
32
|
+
dbg("trace context degraded contact=%s traceId=%s reason=%s spanName=send", contact, trace.traceId, trace.reason);
|
|
33
|
+
if (trace.reason === "invalid") {
|
|
34
|
+
console.warn(`[agent-network:conversation-manager] invalid traceparent contact=${contact} traceId=${trace.traceId} spanName=send`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
29
37
|
try {
|
|
30
|
-
const ack = await this.client.send(address, content, "text", metadata);
|
|
38
|
+
const ack = await this.client.send(address, content, "text", trace.metadata);
|
|
31
39
|
this.ensureConversationEntry(this.extractHandle(address), address, "local");
|
|
32
|
-
dbg("send contact=%s address=%s status=%s", contact, address, ack.status);
|
|
40
|
+
dbg("send contact=%s address=%s status=%s traceId=%s spanName=send", contact, address, ack.status, trace.traceId);
|
|
33
41
|
return { status: "sent" };
|
|
34
42
|
}
|
|
35
43
|
catch (err) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { AUTHORIZED_TOKEN_TTL_MS, SETUP_CODE_CHARSET, SETUP_CODE_LENGTH, SETUP_CODE_TTL_MS, } from "./constants.js";
|
|
2
2
|
export type { AgentNetworkAccount } from "./config-schema.js";
|
|
3
|
-
export type { AddressedMessageEvent, DeliveryPendingEvent, DeliveryStatusEvent, RegisterAckEvent, SendAckEvent, StructuredErrorEvent, } from "./types.js";
|
|
3
|
+
export type { AddressedMessageEvent, DeliveryPendingEvent, DeliverySkipEvent, DeliveryStatusEvent, RegisterAckEvent, SendAckEvent, StructuredErrorEvent, } from "./types.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAIxB,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAIxB,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -8,6 +8,11 @@ export declare class PlatformApiError extends Error {
|
|
|
8
8
|
readonly code: string;
|
|
9
9
|
constructor(status: number, code: string, message: string);
|
|
10
10
|
}
|
|
11
|
+
export declare class PlatformNetworkError extends Error {
|
|
12
|
+
readonly code: "timeout" | "network";
|
|
13
|
+
readonly detail: string;
|
|
14
|
+
constructor(code: "timeout" | "network", detail: string);
|
|
15
|
+
}
|
|
11
16
|
export interface RequestConnectionResponse {
|
|
12
17
|
requestIds: string[];
|
|
13
18
|
status: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-client.d.ts","sourceRoot":"","sources":["../src/platform-client.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,gBAAgB,0BAA0B,CAAC;AASxD,eAAO,MAAM,qBAAqB,iDACc,CAAC;AAEjD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,qBAAa,gBAAiB,SAAQ,KAAK;aAEvB,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,MAAM;gBADZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM;CAKlB;AAMD,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB;AAQD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB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BAAiB,CACrC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,CAAC,YAAY,GAAG,SAAS,CAAC,EAAE,CAAA;CAAE,GACvE,OAAO,CAAC,yBAAyB,CAAC,CAWpC;AAQD,wBAAsB,YAAY,CAChC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GACA,OAAO,CAAC,oBAAoB,CAAC,CAc/B;AAOD,wBAAsB,aAAa,CACjC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,CAAC,CAUhC;AAOD,wBAAsB,cAAc,CAClC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,sBAAsB,CAAC,CAUjC;AAQD,wBAAsB,aAAa,CACjC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,qBAAqB,CAAC,CAWhC;AAQD,wBAAsB,eAAe,CACnC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,uBAAuB,CAAC,CAMlC"}
|
package/dist/platform-client.js
CHANGED
|
@@ -10,6 +10,16 @@ export class PlatformApiError extends Error {
|
|
|
10
10
|
this.name = "PlatformApiError";
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
export class PlatformNetworkError extends Error {
|
|
14
|
+
code;
|
|
15
|
+
detail;
|
|
16
|
+
constructor(code, detail) {
|
|
17
|
+
super(`network ${code}: ${detail}`);
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.detail = detail;
|
|
20
|
+
this.name = "PlatformNetworkError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
13
23
|
function baseUrl(cfg) {
|
|
14
24
|
const trimmed = cfg.apiHost.replace(/\/+$/, "");
|
|
15
25
|
const origin = /^https?:\/\//.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
@@ -21,8 +31,50 @@ async function handleError(res) {
|
|
|
21
31
|
const message = typeof body.message === "string" ? body.message : res.statusText;
|
|
22
32
|
throw new PlatformApiError(res.status, code, message);
|
|
23
33
|
}
|
|
34
|
+
const REQUEST_TIMEOUT_MS = 15_000;
|
|
35
|
+
function causeCode(cause) {
|
|
36
|
+
if (cause && typeof cause === "object" && "code" in cause) {
|
|
37
|
+
const code = cause.code;
|
|
38
|
+
if (typeof code === "string")
|
|
39
|
+
return code;
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
function isTimeoutCode(code) {
|
|
44
|
+
return (code === "ETIMEDOUT" ||
|
|
45
|
+
code === "UND_ERR_CONNECT_TIMEOUT" ||
|
|
46
|
+
code === "UND_ERR_HEADERS_TIMEOUT" ||
|
|
47
|
+
code === "UND_ERR_BODY_TIMEOUT");
|
|
48
|
+
}
|
|
49
|
+
function toNetworkError(err) {
|
|
50
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
51
|
+
return new PlatformNetworkError("timeout", `timed out after ${REQUEST_TIMEOUT_MS}ms`);
|
|
52
|
+
}
|
|
53
|
+
if (err instanceof TypeError && err.message === "fetch failed") {
|
|
54
|
+
const cause = err.cause;
|
|
55
|
+
const code = causeCode(cause);
|
|
56
|
+
const detail = cause instanceof Error && cause.message
|
|
57
|
+
? cause.message
|
|
58
|
+
: code || "fetch failed";
|
|
59
|
+
return new PlatformNetworkError(isTimeoutCode(code) ? "timeout" : "network", detail);
|
|
60
|
+
}
|
|
61
|
+
return err;
|
|
62
|
+
}
|
|
63
|
+
async function apiFetch(url, init = {}) {
|
|
64
|
+
const controller = new AbortController();
|
|
65
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
66
|
+
try {
|
|
67
|
+
return await fetch(url, { ...init, signal: controller.signal });
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
throw toNetworkError(err);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
24
76
|
export async function requestConnection(cfg, runtimeKey, params) {
|
|
25
|
-
const res = await
|
|
77
|
+
const res = await apiFetch(`${baseUrl(cfg)}/me/connections/requests`, {
|
|
26
78
|
method: "POST",
|
|
27
79
|
headers: {
|
|
28
80
|
"Content-Type": "application/json",
|
|
@@ -46,7 +98,7 @@ export async function listRequests(cfg, runtimeKey, params) {
|
|
|
46
98
|
query.set("limit", String(params.limit));
|
|
47
99
|
const qs = query.toString();
|
|
48
100
|
const url = `${baseUrl(cfg)}/me/connections/requests${qs ? `?${qs}` : ""}`;
|
|
49
|
-
const res = await
|
|
101
|
+
const res = await apiFetch(url, {
|
|
50
102
|
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
51
103
|
});
|
|
52
104
|
if (!res.ok)
|
|
@@ -54,7 +106,7 @@ export async function listRequests(cfg, runtimeKey, params) {
|
|
|
54
106
|
return (await res.json());
|
|
55
107
|
}
|
|
56
108
|
export async function acceptRequest(cfg, runtimeKey, requestId) {
|
|
57
|
-
const res = await
|
|
109
|
+
const res = await apiFetch(`${baseUrl(cfg)}/me/connections/requests/${encodeURIComponent(requestId)}/accept`, {
|
|
58
110
|
method: "POST",
|
|
59
111
|
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
60
112
|
});
|
|
@@ -63,7 +115,7 @@ export async function acceptRequest(cfg, runtimeKey, requestId) {
|
|
|
63
115
|
return (await res.json());
|
|
64
116
|
}
|
|
65
117
|
export async function declineRequest(cfg, runtimeKey, requestId) {
|
|
66
|
-
const res = await
|
|
118
|
+
const res = await apiFetch(`${baseUrl(cfg)}/me/connections/requests/${encodeURIComponent(requestId)}/decline`, {
|
|
67
119
|
method: "POST",
|
|
68
120
|
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
69
121
|
});
|
|
@@ -72,7 +124,7 @@ export async function declineRequest(cfg, runtimeKey, requestId) {
|
|
|
72
124
|
return (await res.json());
|
|
73
125
|
}
|
|
74
126
|
export async function updateProfile(cfg, runtimeKey, params) {
|
|
75
|
-
const res = await
|
|
127
|
+
const res = await apiFetch(`${baseUrl(cfg)}/me/profile`, {
|
|
76
128
|
method: "PATCH",
|
|
77
129
|
headers: {
|
|
78
130
|
"Content-Type": "application/json",
|
|
@@ -85,7 +137,7 @@ export async function updateProfile(cfg, runtimeKey, params) {
|
|
|
85
137
|
return (await res.json());
|
|
86
138
|
}
|
|
87
139
|
export async function listConnections(cfg, runtimeKey) {
|
|
88
|
-
const res = await
|
|
140
|
+
const res = await apiFetch(`${baseUrl(cfg)}/me/connections`, {
|
|
89
141
|
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
90
142
|
});
|
|
91
143
|
if (!res.ok)
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAsEA,UAAU,WAAW;IACnB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,CACP,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,UAAU,WAAW;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;AAE3E,UAAU,OAAO;IACf,YAAY,CACV,IAAI,EAAE,cAAc,GAAG,WAAW,EAClC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3C,IAAI,CAAC;CACT;AAoDD,wBAAgB,qBAAqB,IAAI,IAAI,CAG5C;AAwSD,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CA01BhD"}
|
package/dist/tools.js
CHANGED
|
@@ -4,7 +4,7 @@ import { _resetChannelSetupForTesting, consumeChannelSetupStatus, getDefaultChan
|
|
|
4
4
|
import { clearTargetHandle, extractNetworkConfig, getDmScope, getPendingTarget, isProfileNeeded, markProfileComplete, removeIdentityLinks, requireApiKey, requireConversationManager, requirePlatformConfig, writeIdentityLinks, } from "./config.js";
|
|
5
5
|
import { getOwnerHandle } from "./environment-context.js";
|
|
6
6
|
import { ownerNotesQueue } from "./owner-notes.js";
|
|
7
|
-
import { acceptRequest, declineRequest, listConnections, listRequests, PlatformApiError, requestConnection, updateProfile, } from "./platform-client.js";
|
|
7
|
+
import { acceptRequest, declineRequest, listConnections, listRequests, PlatformApiError, PlatformNetworkError, requestConnection, updateProfile, } from "./platform-client.js";
|
|
8
8
|
import { sentMessageBuffer } from "./sent-message-buffer.js";
|
|
9
9
|
import { getCurrentTurnChannelId, getCurrentTurnIsOwnerNonConsuming, getCurrentTurnOwnerSignal, } from "./turn-context.js";
|
|
10
10
|
import { getLatestPublishedVersion, getPluginVersion, getUpdateInfo, } from "./update-check.js";
|
|
@@ -21,6 +21,14 @@ export function _resetToolsForTesting() {
|
|
|
21
21
|
function textResult(text) {
|
|
22
22
|
return { content: [{ type: "text", text }] };
|
|
23
23
|
}
|
|
24
|
+
function networkErrorText(err) {
|
|
25
|
+
const lead = err.code === "timeout"
|
|
26
|
+
? "The request to the MASONS network timed out"
|
|
27
|
+
: "Couldn't reach the MASONS network";
|
|
28
|
+
return (`${lead} (${err.detail}). The request did not reach the server, so this ` +
|
|
29
|
+
"is a connectivity failure, not an empty result. Retry shortly; if it " +
|
|
30
|
+
"persists, check network access to the API host.");
|
|
31
|
+
}
|
|
24
32
|
let updateNoticeShown = false;
|
|
25
33
|
function maybeAppendUpdateNotice(result) {
|
|
26
34
|
const info = getUpdateInfo();
|
|
@@ -297,6 +305,9 @@ export function registerTools(api) {
|
|
|
297
305
|
return textResult(`Validation error: ${err.message}`);
|
|
298
306
|
}
|
|
299
307
|
}
|
|
308
|
+
if (err instanceof PlatformNetworkError) {
|
|
309
|
+
return textResult(networkErrorText(err));
|
|
310
|
+
}
|
|
300
311
|
throw err;
|
|
301
312
|
}
|
|
302
313
|
if (result.profile) {
|
|
@@ -368,6 +379,9 @@ export function registerTools(api) {
|
|
|
368
379
|
}
|
|
369
380
|
return textResult(`Connection request failed: ${err.message}`);
|
|
370
381
|
}
|
|
382
|
+
if (err instanceof PlatformNetworkError) {
|
|
383
|
+
return textResult(networkErrorText(err));
|
|
384
|
+
}
|
|
371
385
|
throw err;
|
|
372
386
|
}
|
|
373
387
|
if (getPendingTarget()) {
|
|
@@ -407,6 +421,9 @@ export function registerTools(api) {
|
|
|
407
421
|
}
|
|
408
422
|
return textResult(`Failed to list requests: ${err.message}`);
|
|
409
423
|
}
|
|
424
|
+
if (err instanceof PlatformNetworkError) {
|
|
425
|
+
return textResult(networkErrorText(err));
|
|
426
|
+
}
|
|
410
427
|
throw err;
|
|
411
428
|
}
|
|
412
429
|
if (result.total === 0) {
|
|
@@ -479,6 +496,9 @@ export function registerTools(api) {
|
|
|
479
496
|
if (err instanceof PlatformApiError && err.status === 404) {
|
|
480
497
|
return textResult("Request not found or already processed. Use masons_list_requests to see current requests.");
|
|
481
498
|
}
|
|
499
|
+
if (err instanceof PlatformNetworkError) {
|
|
500
|
+
return textResult(networkErrorText(err));
|
|
501
|
+
}
|
|
482
502
|
throw err;
|
|
483
503
|
}
|
|
484
504
|
}),
|
|
@@ -503,6 +523,9 @@ export function registerTools(api) {
|
|
|
503
523
|
if (err instanceof PlatformApiError && err.status === 404) {
|
|
504
524
|
return textResult("Request not found or already processed. Use masons_list_requests to see current requests.");
|
|
505
525
|
}
|
|
526
|
+
if (err instanceof PlatformNetworkError) {
|
|
527
|
+
return textResult(networkErrorText(err));
|
|
528
|
+
}
|
|
506
529
|
throw err;
|
|
507
530
|
}
|
|
508
531
|
}),
|
|
@@ -525,6 +548,9 @@ export function registerTools(api) {
|
|
|
525
548
|
}
|
|
526
549
|
return textResult(`Failed to list connections: ${err.message}`);
|
|
527
550
|
}
|
|
551
|
+
if (err instanceof PlatformNetworkError) {
|
|
552
|
+
return textResult(networkErrorText(err));
|
|
553
|
+
}
|
|
528
554
|
throw err;
|
|
529
555
|
}
|
|
530
556
|
if (result.total === 0) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type TraceparentReason } from "./_vendor/trace-context.js";
|
|
2
|
+
export interface TraceMetadataResult {
|
|
3
|
+
metadata: Record<string, unknown>;
|
|
4
|
+
traceId: string;
|
|
5
|
+
degraded: boolean;
|
|
6
|
+
reason: TraceparentReason;
|
|
7
|
+
}
|
|
8
|
+
export declare function ensureTraceMetadata(metadata: Record<string, unknown> | undefined): TraceMetadataResult;
|
|
9
|
+
export interface ReplyTraceMetadataResult {
|
|
10
|
+
metadata: Record<string, unknown>;
|
|
11
|
+
traceId: string;
|
|
12
|
+
originalTraceId?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function createReplyTraceMetadata(inboundMetadata: Record<string, unknown>, replyMetadata?: Record<string, unknown>): ReplyTraceMetadataResult;
|
|
15
|
+
//# sourceMappingURL=trace-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-metadata.d.ts","sourceRoot":"","sources":["../src/trace-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAUD,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC5C,mBAAmB,CAWrB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,aAAa,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAC1C,wBAAwB,CAkB1B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ensureTraceparent, extractTraceId, mintTraceparent, } from "./_vendor/trace-context.js";
|
|
2
|
+
function readTraceparent(metadata) {
|
|
3
|
+
return typeof metadata?.traceparent === "string"
|
|
4
|
+
? metadata.traceparent
|
|
5
|
+
: undefined;
|
|
6
|
+
}
|
|
7
|
+
export function ensureTraceMetadata(metadata) {
|
|
8
|
+
const ensured = ensureTraceparent(readTraceparent(metadata));
|
|
9
|
+
return {
|
|
10
|
+
metadata: {
|
|
11
|
+
...(metadata ?? {}),
|
|
12
|
+
traceparent: ensured.traceparent,
|
|
13
|
+
},
|
|
14
|
+
traceId: ensured.traceId,
|
|
15
|
+
degraded: ensured.degraded,
|
|
16
|
+
reason: ensured.reason,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function createReplyTraceMetadata(inboundMetadata, replyMetadata = {}) {
|
|
20
|
+
const traceparent = mintTraceparent();
|
|
21
|
+
const traceId = extractTraceId(traceparent);
|
|
22
|
+
if (traceId === null) {
|
|
23
|
+
throw new Error("mintTraceparent returned an invalid traceparent");
|
|
24
|
+
}
|
|
25
|
+
const originalTraceId = extractTraceId(readTraceparent(inboundMetadata));
|
|
26
|
+
const { originalTraceId: _ignoredOriginalTraceId, ...safeReplyMetadata } = replyMetadata;
|
|
27
|
+
return {
|
|
28
|
+
metadata: {
|
|
29
|
+
...safeReplyMetadata,
|
|
30
|
+
traceparent,
|
|
31
|
+
...(originalTraceId !== null && { originalTraceId }),
|
|
32
|
+
},
|
|
33
|
+
traceId,
|
|
34
|
+
...(originalTraceId !== null && { originalTraceId }),
|
|
35
|
+
};
|
|
36
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const CURRENT_PROTOCOL_VERSION =
|
|
1
|
+
export declare const CURRENT_PROTOCOL_VERSION = 4;
|
|
2
2
|
export declare const REGISTER_ACK_TIMEOUT_MS = 15000;
|
|
3
3
|
export declare const SEND_ACK_TIMEOUT_MS = 15000;
|
|
4
4
|
export interface RegisterEvent {
|
|
@@ -6,6 +6,7 @@ export interface RegisterEvent {
|
|
|
6
6
|
token: string;
|
|
7
7
|
protocolVersion: number;
|
|
8
8
|
clientVersion?: string;
|
|
9
|
+
runtimeSessionId?: string;
|
|
9
10
|
lastKnownSeq?: number;
|
|
10
11
|
}
|
|
11
12
|
export interface AddressedSendEvent {
|
|
@@ -23,10 +24,12 @@ export interface AddressedTypingEvent {
|
|
|
23
24
|
}
|
|
24
25
|
export interface AddressedDeliveryAckEvent {
|
|
25
26
|
event: "DELIVERY_ACK";
|
|
27
|
+
runtimeSessionId?: string;
|
|
26
28
|
upToSeq: number;
|
|
27
29
|
}
|
|
28
30
|
export interface RequestGapFillEvent {
|
|
29
31
|
event: "REQUEST_GAP_FILL";
|
|
32
|
+
runtimeSessionId?: string;
|
|
30
33
|
sinceSeq: number;
|
|
31
34
|
}
|
|
32
35
|
export interface RegisterAckEvent {
|
|
@@ -52,6 +55,7 @@ export interface SendAckEvent {
|
|
|
52
55
|
export interface AddressedMessageEvent {
|
|
53
56
|
event: "MESSAGE_RECEIVED";
|
|
54
57
|
messageId?: string;
|
|
58
|
+
runtimeSessionId?: string;
|
|
55
59
|
from: string;
|
|
56
60
|
content: string;
|
|
57
61
|
contentType: string;
|
|
@@ -86,16 +90,26 @@ export interface DeliveryStatusEvent {
|
|
|
86
90
|
}
|
|
87
91
|
export interface DeliveryCursorEvent {
|
|
88
92
|
event: "DELIVERY_CURSOR";
|
|
93
|
+
runtimeSessionId?: string;
|
|
89
94
|
deliverySeq: number;
|
|
90
95
|
deliveredSeq?: number;
|
|
91
96
|
}
|
|
97
|
+
export interface DeliverySkipEvent {
|
|
98
|
+
event: "DELIVERY_SKIP";
|
|
99
|
+
runtimeSessionId?: string;
|
|
100
|
+
seq: number;
|
|
101
|
+
reason: "runtime_mailbox_dismissed";
|
|
102
|
+
messageId?: string;
|
|
103
|
+
deliveredAt?: string;
|
|
104
|
+
}
|
|
92
105
|
export type PluginToConnectorEvent = RegisterEvent | AddressedSendEvent | AddressedTypingEvent | AddressedDeliveryAckEvent | RequestGapFillEvent;
|
|
93
|
-
export type ConnectorToPluginEvent = RegisterAckEvent | SendAckEvent | AddressedMessageEvent | DeliveryPendingEvent | DeliveryStatusEvent | DeliveryCursorEvent | StructuredErrorEvent;
|
|
106
|
+
export type ConnectorToPluginEvent = RegisterAckEvent | SendAckEvent | AddressedMessageEvent | DeliveryPendingEvent | DeliveryStatusEvent | DeliveryCursorEvent | DeliverySkipEvent | StructuredErrorEvent;
|
|
94
107
|
export declare function isRegisterAck(data: unknown): data is RegisterAckEvent;
|
|
95
108
|
export declare function isSendAck(data: unknown): data is SendAckEvent;
|
|
96
109
|
export declare function isAddressedMessage(data: unknown): data is AddressedMessageEvent;
|
|
97
110
|
export declare function isDeliveryPending(data: unknown): data is DeliveryPendingEvent;
|
|
98
111
|
export declare function isDeliveryStatus(data: unknown): data is DeliveryStatusEvent;
|
|
99
112
|
export declare function isDeliveryCursor(data: unknown): data is DeliveryCursorEvent;
|
|
113
|
+
export declare function isDeliverySkip(data: unknown): data is DeliverySkipEvent;
|
|
100
114
|
export declare function isStructuredError(data: unknown): data is StructuredErrorEvent;
|
|
101
115
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAQ1C,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAQ1C,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,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L_VERSION =
|
|
1
|
+
export const CURRENT_PROTOCOL_VERSION = 4;
|
|
2
2
|
export const REGISTER_ACK_TIMEOUT_MS = 15_000;
|
|
3
3
|
export const SEND_ACK_TIMEOUT_MS = 15_000;
|
|
4
4
|
function isObject(data) {
|
|
5
5
|
return typeof data === "object" && data !== null;
|
|
6
6
|
}
|
|
7
|
+
function hasValidOptionalRuntimeSessionId(data) {
|
|
8
|
+
return (data.runtimeSessionId === undefined ||
|
|
9
|
+
(typeof data.runtimeSessionId === "string" &&
|
|
10
|
+
data.runtimeSessionId.trim().length > 0));
|
|
11
|
+
}
|
|
7
12
|
export function isRegisterAck(data) {
|
|
8
13
|
return isObject(data) && data.event === "REGISTER_ACK";
|
|
9
14
|
}
|
|
@@ -15,6 +20,7 @@ export function isSendAck(data) {
|
|
|
15
20
|
export function isAddressedMessage(data) {
|
|
16
21
|
return (isObject(data) &&
|
|
17
22
|
data.event === "MESSAGE_RECEIVED" &&
|
|
23
|
+
hasValidOptionalRuntimeSessionId(data) &&
|
|
18
24
|
(data.messageId === undefined || typeof data.messageId === "string") &&
|
|
19
25
|
typeof data.from === "string" &&
|
|
20
26
|
typeof data.content === "string");
|
|
@@ -34,6 +40,7 @@ export function isDeliveryStatus(data) {
|
|
|
34
40
|
export function isDeliveryCursor(data) {
|
|
35
41
|
return (isObject(data) &&
|
|
36
42
|
data.event === "DELIVERY_CURSOR" &&
|
|
43
|
+
hasValidOptionalRuntimeSessionId(data) &&
|
|
37
44
|
typeof data.deliverySeq === "number" &&
|
|
38
45
|
Number.isInteger(data.deliverySeq) &&
|
|
39
46
|
data.deliverySeq >= 0 &&
|
|
@@ -42,6 +49,17 @@ export function isDeliveryCursor(data) {
|
|
|
42
49
|
Number.isInteger(data.deliveredSeq) &&
|
|
43
50
|
data.deliveredSeq >= 0)));
|
|
44
51
|
}
|
|
52
|
+
export function isDeliverySkip(data) {
|
|
53
|
+
return (isObject(data) &&
|
|
54
|
+
data.event === "DELIVERY_SKIP" &&
|
|
55
|
+
hasValidOptionalRuntimeSessionId(data) &&
|
|
56
|
+
typeof data.seq === "number" &&
|
|
57
|
+
Number.isInteger(data.seq) &&
|
|
58
|
+
data.seq >= 0 &&
|
|
59
|
+
data.reason === "runtime_mailbox_dismissed" &&
|
|
60
|
+
(data.messageId === undefined || typeof data.messageId === "string") &&
|
|
61
|
+
(data.deliveredAt === undefined || typeof data.deliveredAt === "string"));
|
|
62
|
+
}
|
|
45
63
|
export function isStructuredError(data) {
|
|
46
64
|
return (isObject(data) &&
|
|
47
65
|
data.event === "ERROR" &&
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PLUGIN_VERSION = "0.6.
|
|
1
|
+
export declare const PLUGIN_VERSION = "0.6.5";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PLUGIN_VERSION = "0.6.
|
|
1
|
+
export const PLUGIN_VERSION = "0.6.5";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@masons/agent-network",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "MASONS Agent Network — OpenClaw channel plugin for connecting agent runtimes to the Agent Network over MSTP.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MASONS.ai <hello@masons.ai> (https://masons.ai)",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc",
|
|
26
26
|
"dev": "tsc --watch",
|
|
27
|
-
"test": "tsc -p test/tsconfig.json && node --test --loader ts-node/esm 'test/**/*.test.ts'",
|
|
27
|
+
"test": "node ../../scripts/sync-vendored-trace-context.mjs && tsc -p test/tsconfig.json && node --test --loader ts-node/esm 'test/**/*.test.ts'",
|
|
28
28
|
"lint": "biome check",
|
|
29
29
|
"format": "biome format --write",
|
|
30
|
-
"prepublishOnly": "bash scripts/check-version.sh && npm run build && npm run test",
|
|
30
|
+
"prepublishOnly": "node ../../scripts/sync-vendored-trace-context.mjs && bash scripts/check-version.sh && npm run build && npm run test",
|
|
31
31
|
"release": "pnpm publish --access public"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|