agents 0.7.0 → 0.7.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.
@@ -7,6 +7,17 @@ type BaseEvent<
7
7
  Payload extends Record<string, unknown> = Record<string, never>
8
8
  > = {
9
9
  type: T;
10
+ /**
11
+ * The class name of the agent that emitted this event
12
+ * (e.g. "MyChatAgent").
13
+ * Always present on events emitted by an Agent instance.
14
+ */
15
+ agent?: string;
16
+ /**
17
+ * The instance name (Durable Object ID name) of the agent.
18
+ * Always present on events emitted by an Agent instance.
19
+ */
20
+ name?: string;
10
21
  /**
11
22
  * The payload of the event
12
23
  */
@@ -145,6 +156,13 @@ type AgentObservabilityEvent =
145
156
  attempts: number;
146
157
  }
147
158
  >
159
+ | BaseEvent<
160
+ "queue:create",
161
+ {
162
+ callback: string;
163
+ id: string;
164
+ }
165
+ >
148
166
  | BaseEvent<
149
167
  "queue:retry",
150
168
  {
@@ -170,6 +188,30 @@ type AgentObservabilityEvent =
170
188
  connectionId: string;
171
189
  }
172
190
  >
191
+ | BaseEvent<
192
+ "disconnect",
193
+ {
194
+ connectionId: string;
195
+ code: number;
196
+ reason: string;
197
+ }
198
+ >
199
+ | BaseEvent<
200
+ "email:receive",
201
+ {
202
+ from: string;
203
+ to: string;
204
+ subject?: string;
205
+ }
206
+ >
207
+ | BaseEvent<
208
+ "email:reply",
209
+ {
210
+ from: string;
211
+ to: string;
212
+ subject?: string;
213
+ }
214
+ >
173
215
  | BaseEvent<
174
216
  "workflow:start",
175
217
  {
@@ -228,4 +270,4 @@ type AgentObservabilityEvent =
228
270
  >;
229
271
  //#endregion
230
272
  export { MCPObservabilityEvent as n, AgentObservabilityEvent as t };
231
- //# sourceMappingURL=agent-DnmmRjyv.d.ts.map
273
+ //# sourceMappingURL=agent-eZnMHidZ.d.ts.map
@@ -1,4 +1,4 @@
1
- import { n as MCPObservabilityEvent } from "./agent-DnmmRjyv.js";
1
+ import { n as MCPObservabilityEvent } from "./agent-eZnMHidZ.js";
2
2
  import { AgentMcpOAuthProvider } from "./mcp/do-oauth-client-provider.js";
3
3
  import { McpAgent } from "./mcp/index.js";
4
4
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
@@ -554,7 +554,7 @@ declare class MCPClientConnection {
554
554
  */
555
555
  getTransport(
556
556
  transportType: BaseTransportType
557
- ): StreamableHTTPClientTransport | SSEClientTransport | RPCClientTransport;
557
+ ): RPCClientTransport | SSEClientTransport | StreamableHTTPClientTransport;
558
558
  private tryConnect;
559
559
  private _capabilityErrorHandler;
560
560
  }
@@ -601,4 +601,4 @@ export {
601
601
  MaybePromise as x,
602
602
  StreamableHTTPEdgeClientTransport as y
603
603
  };
604
- //# sourceMappingURL=client-storage-tusTuoSF.d.ts.map
604
+ //# sourceMappingURL=client-storage-yDVwzgfF.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { RetryOptions } from "../retries.js";
2
- import "../client-storage-tusTuoSF.js";
2
+ import "../client-storage-yDVwzgfF.js";
3
3
  import { Agent, Schedule } from "../index.js";
4
4
 
5
5
  //#region src/experimental/forever.d.ts
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import { RetryOptions } from "./retries.js";
7
7
  import {
8
8
  r as MCPConnectionState,
9
9
  w as TransportType
10
- } from "./client-storage-tusTuoSF.js";
10
+ } from "./client-storage-yDVwzgfF.js";
11
11
  import {
12
12
  AgentMcpOAuthProvider,
13
13
  AgentsOAuthProvider,
@@ -23,7 +23,7 @@ import {
23
23
  WorkflowPage,
24
24
  WorkflowQueryCriteria
25
25
  } from "./workflow-types.js";
26
- import { Observability } from "./observability/index.js";
26
+ import { Observability, ObservabilityEvent } from "./observability/index.js";
27
27
  import { MessageType } from "./types.js";
28
28
  import {
29
29
  Connection,
@@ -325,7 +325,10 @@ declare class Agent<
325
325
  * Emit an observability event with auto-generated timestamp.
326
326
  * @internal
327
327
  */
328
- private _emit;
328
+ protected _emit(
329
+ type: ObservabilityEvent["type"],
330
+ payload?: Record<string, unknown>
331
+ ): void;
329
332
  /**
330
333
  * Execute SQL queries against the Agent's database
331
334
  * @template T Type of the returned rows
package/dist/index.js CHANGED
@@ -260,6 +260,8 @@ var Agent = class Agent extends Server {
260
260
  _emit(type, payload = {}) {
261
261
  this.observability?.emit({
262
262
  type,
263
+ agent: this._ParentClass.name,
264
+ name: this.name,
263
265
  payload,
264
266
  timestamp: Date.now()
265
267
  });
@@ -457,7 +459,11 @@ var Agent = class Agent extends Server {
457
459
  this.broadcastMcpServers();
458
460
  }));
459
461
  this._disposables.add(this.mcp.onObservabilityEvent((event) => {
460
- this.observability?.emit(event);
462
+ this.observability?.emit({
463
+ ...event,
464
+ agent: this._ParentClass.name,
465
+ name: this.name
466
+ });
461
467
  }));
462
468
  {
463
469
  const proto = Object.getPrototypeOf(this);
@@ -620,6 +626,22 @@ var Agent = class Agent extends Server {
620
626
  return this._tryCatch(() => _onConnect(connection, ctx));
621
627
  });
622
628
  };
629
+ const _onClose = this.onClose.bind(this);
630
+ this.onClose = (connection, code, reason, wasClean) => {
631
+ return __DO_NOT_USE_WILL_BREAK__agentContext.run({
632
+ agent: this,
633
+ connection,
634
+ request: void 0,
635
+ email: void 0
636
+ }, () => {
637
+ this._emit("disconnect", {
638
+ connectionId: connection.id,
639
+ code,
640
+ reason
641
+ });
642
+ return _onClose(connection, code, reason, wasClean);
643
+ });
644
+ };
623
645
  const _onStart = this.onStart.bind(this);
624
646
  this.onStart = async (props) => {
625
647
  return __DO_NOT_USE_WILL_BREAK__agentContext.run({
@@ -917,6 +939,11 @@ var Agent = class Agent extends Server {
917
939
  request: void 0,
918
940
  email
919
941
  }, async () => {
942
+ this._emit("email:receive", {
943
+ from: email.from,
944
+ to: email.to,
945
+ subject: email.headers.get("subject") ?? void 0
946
+ });
920
947
  if ("onEmail" in this && typeof this.onEmail === "function") return this._tryCatch(() => this.onEmail(email));
921
948
  else {
922
949
  console.log("Received email from:", email.from, "to:", email.to);
@@ -967,6 +994,12 @@ var Agent = class Agent extends Server {
967
994
  raw: msg.asRaw(),
968
995
  to: email.from
969
996
  });
997
+ const rawSubject = email.headers.get("subject");
998
+ this._emit("email:reply", {
999
+ from: email.to,
1000
+ to: email.from,
1001
+ subject: options.subject ?? (rawSubject ? `Re: ${rawSubject}` : void 0)
1002
+ });
970
1003
  });
971
1004
  }
972
1005
  async _tryCatch(fn) {
@@ -1065,6 +1098,10 @@ var Agent = class Agent extends Server {
1065
1098
  INSERT OR REPLACE INTO cf_agents_queues (id, payload, callback, retry_options)
1066
1099
  VALUES (${id}, ${JSON.stringify(payload)}, ${callback}, ${retryJson})
1067
1100
  `;
1101
+ this._emit("queue:create", {
1102
+ callback,
1103
+ id
1104
+ });
1068
1105
  this._flushQueue().catch((e) => {
1069
1106
  console.error("Error flushing queue:", e);
1070
1107
  });