agents 0.0.0-b57e1d9 → 0.0.0-b5aee9f

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.
Files changed (41) hide show
  1. package/README.md +127 -22
  2. package/dist/ai-chat-agent.d.ts +6 -3
  3. package/dist/ai-chat-agent.js +64 -26
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-react.d.ts +11 -9
  6. package/dist/ai-react.js +27 -27
  7. package/dist/ai-react.js.map +1 -1
  8. package/dist/{chunk-MXJNY43J.js → chunk-3IQQY2UH.js} +614 -129
  9. package/dist/chunk-3IQQY2UH.js.map +1 -0
  10. package/dist/{chunk-VCSB47AK.js → chunk-KUH345EY.js} +8 -8
  11. package/dist/chunk-KUH345EY.js.map +1 -0
  12. package/dist/{chunk-BZXOAZUX.js → chunk-PVQZBKN7.js} +5 -5
  13. package/dist/chunk-PVQZBKN7.js.map +1 -0
  14. package/dist/{chunk-OYJXQRRH.js → chunk-UNG3FXYX.js} +79 -19
  15. package/dist/chunk-UNG3FXYX.js.map +1 -0
  16. package/dist/client.d.ts +2 -2
  17. package/dist/client.js +1 -1
  18. package/dist/index-CLW1aEBr.d.ts +615 -0
  19. package/dist/index.d.ts +35 -405
  20. package/dist/index.js +10 -4
  21. package/dist/mcp/client.d.ts +290 -19
  22. package/dist/mcp/client.js +1 -1
  23. package/dist/mcp/do-oauth-client-provider.js +1 -1
  24. package/dist/mcp/index.d.ts +34 -11
  25. package/dist/mcp/index.js +66 -50
  26. package/dist/mcp/index.js.map +1 -1
  27. package/dist/observability/index.d.ts +14 -0
  28. package/dist/observability/index.js +10 -0
  29. package/dist/observability/index.js.map +1 -0
  30. package/dist/react.d.ts +10 -8
  31. package/dist/react.js +7 -7
  32. package/dist/react.js.map +1 -1
  33. package/dist/schedule.d.ts +6 -6
  34. package/dist/schedule.js +4 -4
  35. package/dist/schedule.js.map +1 -1
  36. package/package.json +76 -71
  37. package/src/index.ts +801 -160
  38. package/dist/chunk-BZXOAZUX.js.map +0 -1
  39. package/dist/chunk-MXJNY43J.js.map +0 -1
  40. package/dist/chunk-OYJXQRRH.js.map +0 -1
  41. package/dist/chunk-VCSB47AK.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MCPClientManager,
3
3
  getNamespacedData
4
- } from "../chunk-OYJXQRRH.js";
4
+ } from "../chunk-UNG3FXYX.js";
5
5
  export {
6
6
  MCPClientManager,
7
7
  getNamespacedData
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DurableObjectOAuthClientProvider
3
- } from "../chunk-BZXOAZUX.js";
3
+ } from "../chunk-PVQZBKN7.js";
4
4
  export {
5
5
  DurableObjectOAuthClientProvider
6
6
  };
@@ -1,17 +1,40 @@
1
1
  import { MCPClientManager } from './client.js';
2
2
  import { DurableObject } from 'cloudflare:workers';
3
- import { Connection, WSMessage } from 'partyserver';
4
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
3
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { Connection, WSMessage } from 'partyserver';
6
+ import { SSEClientTransport, SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
7
+ import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
6
8
  import 'zod';
7
- import '@modelcontextprotocol/sdk/types.js';
8
9
  import '@modelcontextprotocol/sdk/client/index.js';
9
- import '@modelcontextprotocol/sdk/client/sse.js';
10
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
11
+ import '@modelcontextprotocol/sdk/types.js';
12
+ import 'ai';
10
13
  import './do-oauth-client-provider.js';
11
14
  import '@modelcontextprotocol/sdk/client/auth.js';
12
15
  import '@modelcontextprotocol/sdk/shared/auth.js';
13
- import '@modelcontextprotocol/sdk/shared/protocol.js';
14
- import 'ai';
16
+
17
+ declare class SSEEdgeClientTransport extends SSEClientTransport {
18
+ private authProvider;
19
+ /**
20
+ * Creates a new EdgeSSEClientTransport, which overrides fetch to be compatible with the CF workers environment
21
+ */
22
+ constructor(url: URL, options: SSEClientTransportOptions);
23
+ authHeaders(): Promise<{
24
+ Authorization: string;
25
+ } | undefined>;
26
+ }
27
+
28
+ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
29
+ private authProvider;
30
+ /**
31
+ * Creates a new StreamableHTTPEdgeClientTransport, which overrides fetch to be compatible with the CF workers environment
32
+ */
33
+ constructor(url: URL, options: StreamableHTTPClientTransportOptions);
34
+ authHeaders(): Promise<{
35
+ Authorization: string;
36
+ } | undefined>;
37
+ }
15
38
 
16
39
  interface CORSOptions {
17
40
  origin?: string;
@@ -57,23 +80,23 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
57
80
  getWebSocket(): WebSocket | null;
58
81
  getWebSocketForResponseID(id: string): WebSocket | null;
59
82
  onMessage(connection: Connection, event: WSMessage): Promise<void>;
60
- onSSEMcpMessage(sessionId: string, request: Request): Promise<Error | null>;
83
+ onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
61
84
  webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
62
85
  webSocketError(ws: WebSocket, error: unknown): Promise<void>;
63
86
  webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
64
- static mount(path: string, { binding, corsOptions, }?: {
87
+ static mount(path: string, { binding, corsOptions }?: {
65
88
  binding?: string;
66
89
  corsOptions?: CORSOptions;
67
90
  }): {
68
91
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
69
92
  };
70
- static serveSSE(path: string, { binding, corsOptions, }?: {
93
+ static serveSSE(path: string, { binding, corsOptions }?: {
71
94
  binding?: string;
72
95
  corsOptions?: CORSOptions;
73
96
  }): {
74
97
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
75
98
  };
76
- static serve(path: string, { binding, corsOptions, }?: {
99
+ static serve(path: string, { binding, corsOptions }?: {
77
100
  binding?: string;
78
101
  corsOptions?: CORSOptions;
79
102
  }): {
@@ -81,4 +104,4 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
81
104
  };
82
105
  }
83
106
 
84
- export { McpAgent };
107
+ export { McpAgent, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport };
package/dist/mcp/index.js CHANGED
@@ -1,29 +1,32 @@
1
1
  import {
2
2
  Agent
3
- } from "../chunk-MXJNY43J.js";
4
- import "../chunk-OYJXQRRH.js";
5
- import "../chunk-BZXOAZUX.js";
6
- import "../chunk-VCSB47AK.js";
3
+ } from "../chunk-3IQQY2UH.js";
4
+ import {
5
+ SSEEdgeClientTransport,
6
+ StreamableHTTPEdgeClientTransport
7
+ } from "../chunk-UNG3FXYX.js";
8
+ import "../chunk-PVQZBKN7.js";
9
+ import "../chunk-KUH345EY.js";
7
10
 
8
11
  // src/mcp/index.ts
9
12
  import { DurableObject } from "cloudflare:workers";
10
13
  import {
11
14
  InitializeRequestSchema,
15
+ JSONRPCMessageSchema,
12
16
  isJSONRPCError,
13
17
  isJSONRPCNotification,
14
18
  isJSONRPCRequest,
15
- isJSONRPCResponse,
16
- JSONRPCMessageSchema
19
+ isJSONRPCResponse
17
20
  } from "@modelcontextprotocol/sdk/types.js";
18
21
  var MAXIMUM_MESSAGE_SIZE_BYTES = 4 * 1024 * 1024;
19
- function corsHeaders(request, corsOptions = {}) {
22
+ function corsHeaders(_request, corsOptions = {}) {
20
23
  const origin = "*";
21
24
  return {
22
- "Access-Control-Allow-Origin": corsOptions.origin || origin,
25
+ "Access-Control-Allow-Headers": corsOptions.headers || "Content-Type, mcp-session-id, mcp-protocol-version",
23
26
  "Access-Control-Allow-Methods": corsOptions.methods || "GET, POST, OPTIONS",
24
- "Access-Control-Allow-Headers": corsOptions.headers || "Content-Type, mcp-session-id",
25
- "Access-Control-Max-Age": (corsOptions.maxAge || 86400).toString(),
26
- "Access-Control-Expose-Headers": corsOptions.exposeHeaders || "mcp-session-id"
27
+ "Access-Control-Allow-Origin": corsOptions.origin || origin,
28
+ "Access-Control-Expose-Headers": corsOptions.exposeHeaders || "mcp-session-id",
29
+ "Access-Control-Max-Age": (corsOptions.maxAge || 86400).toString()
27
30
  };
28
31
  }
29
32
  function isDurableObjectNamespace(namespace) {
@@ -141,6 +144,7 @@ var McpAgent = class _McpAgent extends DurableObject {
141
144
  setState(state) {
142
145
  return this._agent.setState(state);
143
146
  }
147
+ // biome-ignore lint/correctness/noUnusedFunctionParameters: overriden later
144
148
  onStateUpdate(state, source) {
145
149
  }
146
150
  async onStart() {
@@ -287,7 +291,7 @@ var McpAgent = class _McpAgent extends DurableObject {
287
291
  }
288
292
  // All messages received over SSE after the initial connection has been established
289
293
  // will be passed here
290
- async onSSEMcpMessage(sessionId, request) {
294
+ async onSSEMcpMessage(_sessionId, request) {
291
295
  if (this._status !== "started") {
292
296
  await this._initialize();
293
297
  }
@@ -382,9 +386,14 @@ data: ${relativeUrlWithSession}
382
386
  await doStub._init(ctx.props);
383
387
  const upgradeUrl = new URL(request.url);
384
388
  upgradeUrl.pathname = "/sse";
389
+ const existingHeaders = {};
390
+ request.headers.forEach((value, key) => {
391
+ existingHeaders[key] = value;
392
+ });
385
393
  const response = await doStub.fetch(
386
394
  new Request(upgradeUrl, {
387
395
  headers: {
396
+ ...existingHeaders,
388
397
  Upgrade: "websocket",
389
398
  // Required by PartyServer
390
399
  "x-partykit-room": sessionId
@@ -420,10 +429,10 @@ data: ${JSON.stringify(result.data)}
420
429
  onMessage(event).catch(console.error);
421
430
  });
422
431
  ws.addEventListener("error", (error) => {
423
- async function onError(error2) {
432
+ async function onError(_error) {
424
433
  try {
425
434
  await writer.close();
426
- } catch (e) {
435
+ } catch (_e) {
427
436
  }
428
437
  }
429
438
  onError(error).catch(console.error);
@@ -440,9 +449,9 @@ data: ${JSON.stringify(result.data)}
440
449
  });
441
450
  return new Response(readable, {
442
451
  headers: {
443
- "Content-Type": "text/event-stream",
444
452
  "Cache-Control": "no-cache",
445
453
  Connection: "keep-alive",
454
+ "Content-Type": "text/event-stream",
446
455
  ...corsHeaders(request, corsOptions)
447
456
  }
448
457
  });
@@ -478,23 +487,23 @@ data: ${JSON.stringify(result.data)}
478
487
  const error = await doStub.onSSEMcpMessage(sessionId, request);
479
488
  if (error) {
480
489
  return new Response(error.message, {
481
- status: 400,
482
490
  headers: {
483
- "Content-Type": "text/event-stream",
484
491
  "Cache-Control": "no-cache",
485
492
  Connection: "keep-alive",
493
+ "Content-Type": "text/event-stream",
486
494
  ...corsHeaders(request, corsOptions)
487
- }
495
+ },
496
+ status: 400
488
497
  });
489
498
  }
490
499
  return new Response("Accepted", {
491
- status: 202,
492
500
  headers: {
493
- "Content-Type": "text/event-stream",
494
501
  "Cache-Control": "no-cache",
495
502
  Connection: "keep-alive",
503
+ "Content-Type": "text/event-stream",
496
504
  ...corsHeaders(request, corsOptions)
497
- }
505
+ },
506
+ status: 202
498
507
  });
499
508
  }
500
509
  return new Response("Not Found", { status: 404 });
@@ -532,24 +541,24 @@ data: ${JSON.stringify(result.data)}
532
541
  const acceptHeader = request.headers.get("accept");
533
542
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
534
543
  const body2 = JSON.stringify({
535
- jsonrpc: "2.0",
536
544
  error: {
537
545
  code: -32e3,
538
546
  message: "Not Acceptable: Client must accept both application/json and text/event-stream"
539
547
  },
540
- id: null
548
+ id: null,
549
+ jsonrpc: "2.0"
541
550
  });
542
551
  return new Response(body2, { status: 406 });
543
552
  }
544
553
  const ct = request.headers.get("content-type");
545
554
  if (!ct || !ct.includes("application/json")) {
546
555
  const body2 = JSON.stringify({
547
- jsonrpc: "2.0",
548
556
  error: {
549
557
  code: -32e3,
550
558
  message: "Unsupported Media Type: Content-Type must be application/json"
551
559
  },
552
- id: null
560
+ id: null,
561
+ jsonrpc: "2.0"
553
562
  });
554
563
  return new Response(body2, { status: 415 });
555
564
  }
@@ -559,12 +568,12 @@ data: ${JSON.stringify(result.data)}
559
568
  );
560
569
  if (contentLength > MAXIMUM_MESSAGE_SIZE_BYTES) {
561
570
  const body2 = JSON.stringify({
562
- jsonrpc: "2.0",
563
571
  error: {
564
572
  code: -32e3,
565
573
  message: `Request body too large. Maximum size is ${MAXIMUM_MESSAGE_SIZE_BYTES} bytes`
566
574
  },
567
- id: null
575
+ id: null,
576
+ jsonrpc: "2.0"
568
577
  });
569
578
  return new Response(body2, { status: 413 });
570
579
  }
@@ -572,14 +581,14 @@ data: ${JSON.stringify(result.data)}
572
581
  let rawMessage;
573
582
  try {
574
583
  rawMessage = await request.json();
575
- } catch (error) {
584
+ } catch (_error) {
576
585
  const body2 = JSON.stringify({
577
- jsonrpc: "2.0",
578
586
  error: {
579
587
  code: -32700,
580
588
  message: "Parse error: Invalid JSON"
581
589
  },
582
- id: null
590
+ id: null,
591
+ jsonrpc: "2.0"
583
592
  });
584
593
  return new Response(body2, { status: 400 });
585
594
  }
@@ -593,12 +602,12 @@ data: ${JSON.stringify(result.data)}
593
602
  for (const msg of arrayMessage) {
594
603
  if (!JSONRPCMessageSchema.safeParse(msg).success) {
595
604
  const body2 = JSON.stringify({
596
- jsonrpc: "2.0",
597
605
  error: {
598
606
  code: -32700,
599
607
  message: "Parse error: Invalid JSON-RPC message"
600
608
  },
601
- id: null
609
+ id: null,
610
+ jsonrpc: "2.0"
602
611
  });
603
612
  return new Response(body2, { status: 400 });
604
613
  }
@@ -609,34 +618,34 @@ data: ${JSON.stringify(result.data)}
609
618
  );
610
619
  if (isInitializationRequest && sessionId) {
611
620
  const body2 = JSON.stringify({
612
- jsonrpc: "2.0",
613
621
  error: {
614
622
  code: -32600,
615
623
  message: "Invalid Request: Initialization requests must not include a sessionId"
616
624
  },
617
- id: null
625
+ id: null,
626
+ jsonrpc: "2.0"
618
627
  });
619
628
  return new Response(body2, { status: 400 });
620
629
  }
621
630
  if (isInitializationRequest && messages.length > 1) {
622
631
  const body2 = JSON.stringify({
623
- jsonrpc: "2.0",
624
632
  error: {
625
633
  code: -32600,
626
634
  message: "Invalid Request: Only one initialization request is allowed"
627
635
  },
628
- id: null
636
+ id: null,
637
+ jsonrpc: "2.0"
629
638
  });
630
639
  return new Response(body2, { status: 400 });
631
640
  }
632
641
  if (!isInitializationRequest && !sessionId) {
633
642
  const body2 = JSON.stringify({
634
- jsonrpc: "2.0",
635
643
  error: {
636
644
  code: -32e3,
637
645
  message: "Bad Request: Mcp-Session-Id header is required"
638
646
  },
639
- id: null
647
+ id: null,
648
+ jsonrpc: "2.0"
640
649
  });
641
650
  return new Response(body2, { status: 400 });
642
651
  }
@@ -649,12 +658,12 @@ data: ${JSON.stringify(result.data)}
649
658
  await doStub.setInitialized();
650
659
  } else if (!isInitialized) {
651
660
  const body2 = JSON.stringify({
652
- jsonrpc: "2.0",
653
661
  error: {
654
662
  code: -32001,
655
663
  message: "Session not found"
656
664
  },
657
- id: null
665
+ id: null,
666
+ jsonrpc: "2.0"
658
667
  });
659
668
  return new Response(body2, { status: 404 });
660
669
  }
@@ -663,9 +672,14 @@ data: ${JSON.stringify(result.data)}
663
672
  const encoder = new TextEncoder();
664
673
  const upgradeUrl = new URL(request.url);
665
674
  upgradeUrl.pathname = "/streamable-http";
675
+ const existingHeaders = {};
676
+ request.headers.forEach((value, key) => {
677
+ existingHeaders[key] = value;
678
+ });
666
679
  const response = await doStub.fetch(
667
680
  new Request(upgradeUrl, {
668
681
  headers: {
682
+ ...existingHeaders,
669
683
  Upgrade: "websocket",
670
684
  // Required by PartyServer
671
685
  "x-partykit-room": sessionId
@@ -677,12 +691,12 @@ data: ${JSON.stringify(result.data)}
677
691
  console.error("Failed to establish WebSocket connection");
678
692
  await writer.close();
679
693
  const body2 = JSON.stringify({
680
- jsonrpc: "2.0",
681
694
  error: {
682
695
  code: -32001,
683
696
  message: "Failed to establish WebSocket connection"
684
697
  },
685
- id: null
698
+ id: null,
699
+ jsonrpc: "2.0"
686
700
  });
687
701
  return new Response(body2, { status: 500 });
688
702
  }
@@ -715,10 +729,10 @@ data: ${JSON.stringify(result.data)}
715
729
  onMessage(event).catch(console.error);
716
730
  });
717
731
  ws.addEventListener("error", (error) => {
718
- async function onError(error2) {
732
+ async function onError(_error) {
719
733
  try {
720
734
  await writer.close();
721
- } catch (e) {
735
+ } catch (_e) {
722
736
  }
723
737
  }
724
738
  onError(error).catch(console.error);
@@ -742,8 +756,8 @@ data: ${JSON.stringify(result.data)}
742
756
  }
743
757
  ws.close();
744
758
  return new Response(null, {
745
- status: 202,
746
- headers: corsHeaders(request, corsOptions)
759
+ headers: corsHeaders(request, corsOptions),
760
+ status: 202
747
761
  });
748
762
  }
749
763
  for (const message of messages) {
@@ -754,9 +768,9 @@ data: ${JSON.stringify(result.data)}
754
768
  }
755
769
  return new Response(readable, {
756
770
  headers: {
757
- "Content-Type": "text/event-stream",
758
771
  "Cache-Control": "no-cache",
759
772
  Connection: "keep-alive",
773
+ "Content-Type": "text/event-stream",
760
774
  "mcp-session-id": sessionId,
761
775
  ...corsHeaders(request, corsOptions)
762
776
  },
@@ -764,12 +778,12 @@ data: ${JSON.stringify(result.data)}
764
778
  });
765
779
  }
766
780
  const body = JSON.stringify({
767
- jsonrpc: "2.0",
768
781
  error: {
769
782
  code: -32e3,
770
783
  message: "Method not allowed"
771
784
  },
772
- id: null
785
+ id: null,
786
+ jsonrpc: "2.0"
773
787
  });
774
788
  return new Response(body, { status: 405 });
775
789
  }
@@ -777,6 +791,8 @@ data: ${JSON.stringify(result.data)}
777
791
  }
778
792
  };
779
793
  export {
780
- McpAgent
794
+ McpAgent,
795
+ SSEEdgeClientTransport,
796
+ StreamableHTTPEdgeClientTransport
781
797
  };
782
798
  //# sourceMappingURL=index.js.map