@masons/agent-network 0.4.17 → 0.4.18
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/channel.d.ts.map +1 -1
- package/dist/channel.js +3 -1
- package/dist/connector-client.d.ts.map +1 -1
- package/dist/connector-client.js +4 -0
- package/dist/environment-context.d.ts +45 -0
- package/dist/environment-context.d.ts.map +1 -0
- package/dist/environment-context.js +81 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +32 -4
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +10 -11
package/dist/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAuB9D,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,UAAU,oBAAoB,CAAC,CAAC;IAC9B,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAAC;IACvD,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,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,QAAQ,EAAE,sBAAsB,CAAC;IACjC,OAAO,EAAE,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;CACrD;AA+ND,eAAO,MAAM,mBAAmB,EAAE,yBAqNjC,CAAC"}
|
package/dist/channel.js
CHANGED
|
@@ -3,6 +3,7 @@ import createDebug from "debug";
|
|
|
3
3
|
import { clearConnectorClient, clearConversationManager, extractNetworkConfig, initConnectorClient, initConversationManager, initToolConfig, requirePluginRuntime, } from "./config.js";
|
|
4
4
|
import { ConnectorClient } from "./connector-client.js";
|
|
5
5
|
import { ConversationManager } from "./conversation-manager.js";
|
|
6
|
+
import { clearEnvironmentContext } from "./environment-context.js";
|
|
6
7
|
import { extractHandleFromAddress } from "./handle-utils.js";
|
|
7
8
|
import { clearOwnerState, isOwnerAddress, markOwnerAddress, setCurrentTurnIsOwner, } from "./owner-session-state.js";
|
|
8
9
|
import { setCurrentTurnSender } from "./turn-context.js";
|
|
@@ -283,9 +284,10 @@ export const agentNetworkChannel = {
|
|
|
283
284
|
dbg("delivery_pending → ACK sent count=%d upTo=%s", event.count, event.upTo);
|
|
284
285
|
});
|
|
285
286
|
// --- Disconnect ---
|
|
286
|
-
// On disconnect, all
|
|
287
|
+
// On disconnect, all session state is invalid — clear owner + environment.
|
|
287
288
|
client.on("disconnected", () => {
|
|
288
289
|
clearOwnerState();
|
|
290
|
+
clearEnvironmentContext();
|
|
289
291
|
});
|
|
290
292
|
// --- Error handling ---
|
|
291
293
|
// Must register before connect() — unhandled "error" events crash the process.
|
|
@@ -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;
|
|
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,KAA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G,IAAI,EAAE,UAAU,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAC5C,OAAO;IACV,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO;IAOzD,OAAO,CAAC,SAAS;IAmBjB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,aAAa,CAgBnB;IAEF,6CAA6C;IAC7C,OAAO,CAAC,iBAAiB;IAgCzB,OAAO,CAAC,iBAAiB;IAkDzB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAUrB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAoB7B,OAAO,CAAC,WAAW,CAqBjB;IAEF,OAAO,CAAC,WAAW,CAIjB;IAIF,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,iBAAiB;IAqBzB,wCAAwC;IACxC,OAAO,CAAC,SAAS;CAclB"}
|
package/dist/connector-client.js
CHANGED
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
3
|
import createDebug from "debug";
|
|
4
4
|
import WebSocket from "ws";
|
|
5
|
+
import { setEnvironmentContext } from "./environment-context.js";
|
|
5
6
|
import { CURRENT_PROTOCOL_VERSION, isAddressedMessage, isDeliveryPending, isRegisterAck, isSendAck, isStructuredError, REGISTER_ACK_TIMEOUT_MS, SEND_ACK_TIMEOUT_MS, } from "./types.js";
|
|
6
7
|
import { PLUGIN_VERSION } from "./version.js";
|
|
7
8
|
const dbg = createDebug("agent-network:connector");
|
|
@@ -231,6 +232,9 @@ export class ConnectorClient extends EventEmitter {
|
|
|
231
232
|
if (ack.protocolVersion !== CURRENT_PROTOCOL_VERSION) {
|
|
232
233
|
dbg("WARN: server negotiated protocolVersion=%d, expected=%d", ack.protocolVersion, CURRENT_PROTOCOL_VERSION);
|
|
233
234
|
}
|
|
235
|
+
// Store agent + owner identity from enriched REGISTER_ACK (#969).
|
|
236
|
+
// Old Connectors omit these fields — setEnvironmentContext handles undefined.
|
|
237
|
+
setEnvironmentContext(ack.agent, ack.owner);
|
|
234
238
|
this.backoffMs = BACKOFF_INITIAL_MS;
|
|
235
239
|
this.alreadyConnectedRetries = 0;
|
|
236
240
|
this.resolveRegister();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Environment Context — self-identity and owner identity.
|
|
3
|
+
*
|
|
4
|
+
* Populated from REGISTER_ACK when the Connector includes agent/owner fields
|
|
5
|
+
* (#969). Connection-scoped: cleared on disconnect, refreshed on reconnect.
|
|
6
|
+
*
|
|
7
|
+
* Module-level singleton — shared between connector-client.ts (write) and
|
|
8
|
+
* plugin.ts (read). Follows the same pattern as owner-session-state.ts.
|
|
9
|
+
*
|
|
10
|
+
* **Trust model**: Identity is Connector-asserted, not cryptographically
|
|
11
|
+
* verified. The Plugin trusts the Connector because they communicate over an
|
|
12
|
+
* authenticated WebSocket channel. A self-hosted Connector could assert
|
|
13
|
+
* arbitrary identity — this is the same trust level as the `from` field on
|
|
14
|
+
* MESSAGE_RECEIVED. Do not build security-critical logic on these values.
|
|
15
|
+
*/
|
|
16
|
+
export interface AgentIdentity {
|
|
17
|
+
handle: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface OwnerIdentity {
|
|
21
|
+
handle: string;
|
|
22
|
+
displayName?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Store agent and owner identity from an enriched REGISTER_ACK.
|
|
26
|
+
*
|
|
27
|
+
* Either parameter may be undefined (old Connector, or agent without
|
|
28
|
+
* a bound owner). Undefined values leave the corresponding state as null.
|
|
29
|
+
*/
|
|
30
|
+
export declare function setEnvironmentContext(agent?: {
|
|
31
|
+
handle: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
}, owner?: {
|
|
34
|
+
handle: string;
|
|
35
|
+
displayName?: string;
|
|
36
|
+
}): void;
|
|
37
|
+
export declare function getAgentIdentity(): AgentIdentity | null;
|
|
38
|
+
export declare function getOwnerIdentity(): OwnerIdentity | null;
|
|
39
|
+
/** Convenience: get the owner's handle for interaction tagging. */
|
|
40
|
+
export declare function getOwnerHandle(): string | null;
|
|
41
|
+
/** Clear all environment context (connection lost — identity invalid). */
|
|
42
|
+
export declare function clearEnvironmentContext(): void;
|
|
43
|
+
/** @internal Reset module state for test isolation. */
|
|
44
|
+
export declare function _resetForTesting(): void;
|
|
45
|
+
//# sourceMappingURL=environment-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-context.d.ts","sourceRoot":"","sources":["../src/environment-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAaD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EACzC,KAAK,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/C,IAAI,CAkBN;AAMD,wBAAgB,gBAAgB,IAAI,aAAa,GAAG,IAAI,CAEvD;AAED,wBAAgB,gBAAgB,IAAI,aAAa,GAAG,IAAI,CAEvD;AAED,mEAAmE;AACnE,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAE9C;AAMD,0EAA0E;AAC1E,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C;AAMD,uDAAuD;AACvD,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Environment Context — self-identity and owner identity.
|
|
3
|
+
*
|
|
4
|
+
* Populated from REGISTER_ACK when the Connector includes agent/owner fields
|
|
5
|
+
* (#969). Connection-scoped: cleared on disconnect, refreshed on reconnect.
|
|
6
|
+
*
|
|
7
|
+
* Module-level singleton — shared between connector-client.ts (write) and
|
|
8
|
+
* plugin.ts (read). Follows the same pattern as owner-session-state.ts.
|
|
9
|
+
*
|
|
10
|
+
* **Trust model**: Identity is Connector-asserted, not cryptographically
|
|
11
|
+
* verified. The Plugin trusts the Connector because they communicate over an
|
|
12
|
+
* authenticated WebSocket channel. A self-hosted Connector could assert
|
|
13
|
+
* arbitrary identity — this is the same trust level as the `from` field on
|
|
14
|
+
* MESSAGE_RECEIVED. Do not build security-critical logic on these values.
|
|
15
|
+
*/
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// State
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
let agentIdentity = null;
|
|
20
|
+
let ownerIdentity = null;
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Write API (called from connector-client.ts on REGISTER_ACK)
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
/**
|
|
25
|
+
* Store agent and owner identity from an enriched REGISTER_ACK.
|
|
26
|
+
*
|
|
27
|
+
* Either parameter may be undefined (old Connector, or agent without
|
|
28
|
+
* a bound owner). Undefined values leave the corresponding state as null.
|
|
29
|
+
*/
|
|
30
|
+
export function setEnvironmentContext(agent, owner) {
|
|
31
|
+
// Defensive: validate handle is a string even though types say so.
|
|
32
|
+
// A malformed REGISTER_ACK from an untrusted Connector could send
|
|
33
|
+
// non-string values; guard prevents storing garbage in module state.
|
|
34
|
+
if (agent && typeof agent.handle === "string") {
|
|
35
|
+
const identity = { handle: agent.handle };
|
|
36
|
+
if (agent.name)
|
|
37
|
+
identity.name = agent.name;
|
|
38
|
+
agentIdentity = identity;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
agentIdentity = null;
|
|
42
|
+
}
|
|
43
|
+
if (owner && typeof owner.handle === "string") {
|
|
44
|
+
const identity = { handle: owner.handle };
|
|
45
|
+
if (owner.displayName)
|
|
46
|
+
identity.displayName = owner.displayName;
|
|
47
|
+
ownerIdentity = identity;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
ownerIdentity = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Read API (called from plugin.ts in before_prompt_build)
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
export function getAgentIdentity() {
|
|
57
|
+
return agentIdentity;
|
|
58
|
+
}
|
|
59
|
+
export function getOwnerIdentity() {
|
|
60
|
+
return ownerIdentity;
|
|
61
|
+
}
|
|
62
|
+
/** Convenience: get the owner's handle for interaction tagging. */
|
|
63
|
+
export function getOwnerHandle() {
|
|
64
|
+
return ownerIdentity?.handle ?? null;
|
|
65
|
+
}
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// Lifecycle
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
/** Clear all environment context (connection lost — identity invalid). */
|
|
70
|
+
export function clearEnvironmentContext() {
|
|
71
|
+
agentIdentity = null;
|
|
72
|
+
ownerIdentity = null;
|
|
73
|
+
}
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Test-only reset
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
/** @internal Reset module state for test isolation. */
|
|
78
|
+
export function _resetForTesting() {
|
|
79
|
+
agentIdentity = null;
|
|
80
|
+
ownerIdentity = null;
|
|
81
|
+
}
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AA8HA,UAAU,iBAAiB;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjD,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;CACnE;AAED,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;kBA4BI,iBAAiB;CA6UhC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { agentNetworkChannel } from "./channel.js";
|
|
5
5
|
import { configureInteractive } from "./cli-setup.js";
|
|
6
6
|
import { detectPendingState, getConversationManager, getStateCacheGeneration, initPluginRuntime, } from "./config.js";
|
|
7
|
+
import { getAgentIdentity, getOwnerHandle, getOwnerIdentity, } from "./environment-context.js";
|
|
7
8
|
import { ownerNotesQueue } from "./owner-notes.js";
|
|
8
9
|
import { consumeCurrentTurnIsOwner } from "./owner-session-state.js";
|
|
9
10
|
import { sentMessageBuffer } from "./sent-message-buffer.js";
|
|
@@ -43,7 +44,7 @@ const MAX_INTERACTIONS = 5;
|
|
|
43
44
|
*
|
|
44
45
|
* Returns undefined if no interactions exist or CM is not available.
|
|
45
46
|
*/
|
|
46
|
-
function buildInteractionContext(channelId, turnSender) {
|
|
47
|
+
function buildInteractionContext(channelId, turnSender, ownerHandle) {
|
|
47
48
|
const cm = getConversationManager();
|
|
48
49
|
if (!cm)
|
|
49
50
|
return undefined;
|
|
@@ -60,9 +61,12 @@ function buildInteractionContext(channelId, turnSender) {
|
|
|
60
61
|
: "[Active interactions]";
|
|
61
62
|
const lines = sorted.map((c) => {
|
|
62
63
|
const who = `@${c.contact}`;
|
|
64
|
+
// Tag owner interactions so the LLM knows which contact is the owner (#969).
|
|
65
|
+
const isOwner = !!ownerHandle && c.contact.toLowerCase() === ownerHandle.toLowerCase();
|
|
66
|
+
const ownerTag = isOwner ? " (your owner)" : "";
|
|
63
67
|
const initiated = c.initiatedBy === "local" ? "you initiated" : "they initiated";
|
|
64
68
|
const when = formatTimeAgo(c.lastMessageAt);
|
|
65
|
-
return `• ${who} — ${initiated} — last activity ${when}`;
|
|
69
|
+
return `• ${who}${ownerTag} — ${initiated} — last activity ${when}`;
|
|
66
70
|
});
|
|
67
71
|
const isNetworkTurn = channelId === "agent-network";
|
|
68
72
|
if (isNetworkTurn && turnSender) {
|
|
@@ -298,7 +302,7 @@ const plugin = {
|
|
|
298
302
|
"your owner (Principal) will NOT see it. To report something to your owner, " +
|
|
299
303
|
"call masons_note_for_owner.";
|
|
300
304
|
// Append interaction space snapshot if active interactions exist.
|
|
301
|
-
const interactionCtx = buildInteractionContext(channelId, turnSender);
|
|
305
|
+
const interactionCtx = buildInteractionContext(channelId, turnSender, getOwnerHandle());
|
|
302
306
|
if (interactionCtx) {
|
|
303
307
|
dynamicContext += `\n\n${interactionCtx}`;
|
|
304
308
|
}
|
|
@@ -342,7 +346,7 @@ const plugin = {
|
|
|
342
346
|
}
|
|
343
347
|
// Append interaction space on owner turns too (#873).
|
|
344
348
|
// Gives the agent awareness of active network interactions.
|
|
345
|
-
const interactionCtx = buildInteractionContext(channelId, null);
|
|
349
|
+
const interactionCtx = buildInteractionContext(channelId, null, getOwnerHandle());
|
|
346
350
|
if (interactionCtx) {
|
|
347
351
|
dynamicContext = dynamicContext
|
|
348
352
|
? `${dynamicContext}\n\n${interactionCtx}`
|
|
@@ -350,6 +354,30 @@ const plugin = {
|
|
|
350
354
|
}
|
|
351
355
|
}
|
|
352
356
|
}
|
|
357
|
+
// --- Identity preamble (#969) ---
|
|
358
|
+
// Inject agent + owner identity into dynamic context so the LLM knows
|
|
359
|
+
// who it is and who its owner is on the network. Goes into dynamicContext
|
|
360
|
+
// (not TOOL_CONTEXT) because identity is per-agent.
|
|
361
|
+
if (state.hasCredentials) {
|
|
362
|
+
const envAgent = getAgentIdentity();
|
|
363
|
+
const envOwner = getOwnerIdentity();
|
|
364
|
+
if (envAgent) {
|
|
365
|
+
let identityLine = `[Identity] You are @${envAgent.handle}`;
|
|
366
|
+
if (envAgent.name)
|
|
367
|
+
identityLine += ` (${envAgent.name})`;
|
|
368
|
+
identityLine += " on the agent network.";
|
|
369
|
+
if (envOwner) {
|
|
370
|
+
identityLine += ` Your owner is @${envOwner.handle}`;
|
|
371
|
+
if (envOwner.displayName) {
|
|
372
|
+
identityLine += ` (${envOwner.displayName})`;
|
|
373
|
+
}
|
|
374
|
+
identityLine += ".";
|
|
375
|
+
}
|
|
376
|
+
dynamicContext = dynamicContext
|
|
377
|
+
? `${identityLine}\n\n${dynamicContext}`
|
|
378
|
+
: identityLine;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
353
381
|
// Post-upgrade verification: if an update is still available after
|
|
354
382
|
// a gateway restart, the previous upgrade attempt may have failed.
|
|
355
383
|
const updateInfo = getUpdateInfo();
|
package/dist/types.d.ts
CHANGED
|
@@ -32,6 +32,16 @@ export interface RegisterAckEvent {
|
|
|
32
32
|
status: "ok" | "error";
|
|
33
33
|
reason?: string;
|
|
34
34
|
protocolVersion: number;
|
|
35
|
+
/** Agent identity — present when Connector supports environment context (#969). */
|
|
36
|
+
agent?: {
|
|
37
|
+
handle: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
};
|
|
40
|
+
/** Owner identity — present when agent has a bound owner with a MASONS account. */
|
|
41
|
+
owner?: {
|
|
42
|
+
handle: string;
|
|
43
|
+
displayName?: string;
|
|
44
|
+
};
|
|
35
45
|
}
|
|
36
46
|
/**
|
|
37
47
|
* Delivery confirmation for a sent message.
|
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;CACxB;AAED,qDAAqD;AACrD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qDAAqD;AACrD,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,QAAQ,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,iEAAiE;AACjE,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,cAAc,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAID,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"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AAI,IAAI,oBAAoB,CAO7E;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,oBAAoB,CAO7E"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Plugin version — must match package.json. Validated by prepublishOnly. */
|
|
2
|
-
export const PLUGIN_VERSION = "0.4.
|
|
2
|
+
export const PLUGIN_VERSION = "0.4.18";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@masons/agent-network",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"description": "MASONS plugin for OpenClaw — connect your agent to the agent network",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MASONS.ai <hello@masons.ai> (https://masons.ai)",
|
|
@@ -19,15 +19,6 @@
|
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsc",
|
|
24
|
-
"dev": "tsc --watch",
|
|
25
|
-
"test": "tsc -p test/tsconfig.json && node --test --loader ts-node/esm test/**/*.test.ts",
|
|
26
|
-
"lint": "biome check",
|
|
27
|
-
"format": "biome format --write",
|
|
28
|
-
"prepublishOnly": "bash scripts/check-version.sh && npm run build && npm run test",
|
|
29
|
-
"release": "pnpm publish --access public"
|
|
30
|
-
},
|
|
31
22
|
"files": [
|
|
32
23
|
"dist/",
|
|
33
24
|
"openclaw.plugin.json",
|
|
@@ -77,5 +68,13 @@
|
|
|
77
68
|
"@types/ws": "^8",
|
|
78
69
|
"ts-node": "^10",
|
|
79
70
|
"typescript": "^5"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "tsc",
|
|
74
|
+
"dev": "tsc --watch",
|
|
75
|
+
"test": "tsc -p test/tsconfig.json && node --test --loader ts-node/esm test/**/*.test.ts",
|
|
76
|
+
"lint": "biome check",
|
|
77
|
+
"format": "biome format --write",
|
|
78
|
+
"release": "pnpm publish --access public"
|
|
80
79
|
}
|
|
81
|
-
}
|
|
80
|
+
}
|