agents 0.0.0-d1f6c02 → 0.0.0-d40512c

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 (44) hide show
  1. package/README.md +22 -22
  2. package/dist/ai-chat-agent.d.ts +5 -4
  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 +10 -9
  6. package/dist/ai-react.js +27 -27
  7. package/dist/ai-react.js.map +1 -1
  8. package/dist/{chunk-Y67CHZBI.js → chunk-4RBEYCWK.js} +23 -18
  9. package/dist/chunk-4RBEYCWK.js.map +1 -0
  10. package/dist/{chunk-QSGN3REV.js → chunk-KUH345EY.js} +8 -15
  11. package/dist/chunk-KUH345EY.js.map +1 -0
  12. package/dist/{chunk-AXSPGBHI.js → chunk-LU2RSO54.js} +208 -81
  13. package/dist/chunk-LU2RSO54.js.map +1 -0
  14. package/dist/{chunk-BZXOAZUX.js → chunk-PVQZBKN7.js} +5 -5
  15. package/dist/chunk-PVQZBKN7.js.map +1 -0
  16. package/dist/client.d.ts +8 -2
  17. package/dist/client.js +1 -1
  18. package/dist/index-CITGJflw.d.ts +486 -0
  19. package/dist/index.d.ts +25 -405
  20. package/dist/index.js +4 -4
  21. package/dist/mcp/client.d.ts +281 -9
  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 +9 -9
  25. package/dist/mcp/index.js +53 -49
  26. package/dist/mcp/index.js.map +1 -1
  27. package/dist/observability/index.d.ts +12 -0
  28. package/dist/observability/index.js +10 -0
  29. package/dist/observability/index.js.map +1 -0
  30. package/dist/react.d.ts +56 -38
  31. package/dist/react.js +16 -6
  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/dist/serializable.d.ts +32 -0
  37. package/dist/serializable.js +1 -0
  38. package/dist/serializable.js.map +1 -0
  39. package/package.json +75 -72
  40. package/src/index.ts +232 -117
  41. package/dist/chunk-AXSPGBHI.js.map +0 -1
  42. package/dist/chunk-BZXOAZUX.js.map +0 -1
  43. package/dist/chunk-QSGN3REV.js.map +0 -1
  44. package/dist/chunk-Y67CHZBI.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MCPClientManager,
3
3
  getNamespacedData
4
- } from "../chunk-Y67CHZBI.js";
4
+ } from "../chunk-4RBEYCWK.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,17 @@
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
6
  import 'zod';
7
- import '@modelcontextprotocol/sdk/types.js';
8
7
  import '@modelcontextprotocol/sdk/client/index.js';
9
8
  import '@modelcontextprotocol/sdk/client/sse.js';
9
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
10
+ import '@modelcontextprotocol/sdk/types.js';
11
+ import 'ai';
10
12
  import './do-oauth-client-provider.js';
11
13
  import '@modelcontextprotocol/sdk/client/auth.js';
12
14
  import '@modelcontextprotocol/sdk/shared/auth.js';
13
- import '@modelcontextprotocol/sdk/shared/protocol.js';
14
- import 'ai';
15
15
 
16
16
  interface CORSOptions {
17
17
  origin?: string;
@@ -57,23 +57,23 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
57
57
  getWebSocket(): WebSocket | null;
58
58
  getWebSocketForResponseID(id: string): WebSocket | null;
59
59
  onMessage(connection: Connection, event: WSMessage): Promise<void>;
60
- onSSEMcpMessage(sessionId: string, request: Request): Promise<Error | null>;
60
+ onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
61
61
  webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
62
62
  webSocketError(ws: WebSocket, error: unknown): Promise<void>;
63
63
  webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
64
- static mount(path: string, { binding, corsOptions, }?: {
64
+ static mount(path: string, { binding, corsOptions }?: {
65
65
  binding?: string;
66
66
  corsOptions?: CORSOptions;
67
67
  }): {
68
68
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
69
69
  };
70
- static serveSSE(path: string, { binding, corsOptions, }?: {
70
+ static serveSSE(path: string, { binding, corsOptions }?: {
71
71
  binding?: string;
72
72
  corsOptions?: CORSOptions;
73
73
  }): {
74
74
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
75
75
  };
76
- static serve(path: string, { binding, corsOptions, }?: {
76
+ static serve(path: string, { binding, corsOptions }?: {
77
77
  binding?: string;
78
78
  corsOptions?: CORSOptions;
79
79
  }): {
package/dist/mcp/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Agent
3
- } from "../chunk-AXSPGBHI.js";
4
- import "../chunk-BZXOAZUX.js";
5
- import "../chunk-QSGN3REV.js";
6
- import "../chunk-Y67CHZBI.js";
3
+ } from "../chunk-LU2RSO54.js";
4
+ import "../chunk-4RBEYCWK.js";
5
+ import "../chunk-PVQZBKN7.js";
6
+ import "../chunk-KUH345EY.js";
7
7
 
8
8
  // src/mcp/index.ts
9
9
  import { DurableObject } from "cloudflare:workers";
@@ -16,16 +16,19 @@ import {
16
16
  JSONRPCMessageSchema
17
17
  } from "@modelcontextprotocol/sdk/types.js";
18
18
  var MAXIMUM_MESSAGE_SIZE_BYTES = 4 * 1024 * 1024;
19
- function corsHeaders(request, corsOptions = {}) {
19
+ function corsHeaders(_request, corsOptions = {}) {
20
20
  const origin = "*";
21
21
  return {
22
- "Access-Control-Allow-Origin": corsOptions.origin || origin,
22
+ "Access-Control-Allow-Headers": corsOptions.headers || "Content-Type, mcp-session-id, mcp-protocol-version",
23
23
  "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"
24
+ "Access-Control-Allow-Origin": corsOptions.origin || origin,
25
+ "Access-Control-Expose-Headers": corsOptions.exposeHeaders || "mcp-session-id",
26
+ "Access-Control-Max-Age": (corsOptions.maxAge || 86400).toString()
27
27
  };
28
28
  }
29
+ function isDurableObjectNamespace(namespace) {
30
+ return typeof namespace === "object" && namespace !== null && "newUniqueId" in namespace && typeof namespace.newUniqueId === "function" && "idFromName" in namespace && typeof namespace.idFromName === "function";
31
+ }
29
32
  function handleCORS(request, corsOptions) {
30
33
  if (request.method === "OPTIONS") {
31
34
  return new Response(null, { headers: corsHeaders(request, corsOptions) });
@@ -138,6 +141,7 @@ var McpAgent = class _McpAgent extends DurableObject {
138
141
  setState(state) {
139
142
  return this._agent.setState(state);
140
143
  }
144
+ // biome-ignore lint/correctness/noUnusedFunctionParameters: overriden later
141
145
  onStateUpdate(state, source) {
142
146
  }
143
147
  async onStart() {
@@ -284,7 +288,7 @@ var McpAgent = class _McpAgent extends DurableObject {
284
288
  }
285
289
  // All messages received over SSE after the initial connection has been established
286
290
  // will be passed here
287
- async onSSEMcpMessage(sessionId, request) {
291
+ async onSSEMcpMessage(_sessionId, request) {
288
292
  if (this._status !== "started") {
289
293
  await this._initialize();
290
294
  }
@@ -356,7 +360,7 @@ var McpAgent = class _McpAgent extends DurableObject {
356
360
  );
357
361
  return new Response("Invalid binding", { status: 500 });
358
362
  }
359
- if (bindingValue.toString() !== "[object DurableObjectNamespace]") {
363
+ if (!isDurableObjectNamespace(bindingValue)) {
360
364
  return new Response("Invalid binding", { status: 500 });
361
365
  }
362
366
  const namespace = bindingValue;
@@ -417,10 +421,10 @@ data: ${JSON.stringify(result.data)}
417
421
  onMessage(event).catch(console.error);
418
422
  });
419
423
  ws.addEventListener("error", (error) => {
420
- async function onError(error2) {
424
+ async function onError(_error) {
421
425
  try {
422
426
  await writer.close();
423
- } catch (e) {
427
+ } catch (_e) {
424
428
  }
425
429
  }
426
430
  onError(error).catch(console.error);
@@ -437,9 +441,9 @@ data: ${JSON.stringify(result.data)}
437
441
  });
438
442
  return new Response(readable, {
439
443
  headers: {
440
- "Content-Type": "text/event-stream",
441
444
  "Cache-Control": "no-cache",
442
445
  Connection: "keep-alive",
446
+ "Content-Type": "text/event-stream",
443
447
  ...corsHeaders(request, corsOptions)
444
448
  }
445
449
  });
@@ -475,23 +479,23 @@ data: ${JSON.stringify(result.data)}
475
479
  const error = await doStub.onSSEMcpMessage(sessionId, request);
476
480
  if (error) {
477
481
  return new Response(error.message, {
478
- status: 400,
479
482
  headers: {
480
- "Content-Type": "text/event-stream",
481
483
  "Cache-Control": "no-cache",
482
484
  Connection: "keep-alive",
485
+ "Content-Type": "text/event-stream",
483
486
  ...corsHeaders(request, corsOptions)
484
- }
487
+ },
488
+ status: 400
485
489
  });
486
490
  }
487
491
  return new Response("Accepted", {
488
- status: 202,
489
492
  headers: {
490
- "Content-Type": "text/event-stream",
491
493
  "Cache-Control": "no-cache",
492
494
  Connection: "keep-alive",
495
+ "Content-Type": "text/event-stream",
493
496
  ...corsHeaders(request, corsOptions)
494
- }
497
+ },
498
+ status: 202
495
499
  });
496
500
  }
497
501
  return new Response("Not Found", { status: 404 });
@@ -521,7 +525,7 @@ data: ${JSON.stringify(result.data)}
521
525
  );
522
526
  return new Response("Invalid binding", { status: 500 });
523
527
  }
524
- if (bindingValue.toString() !== "[object DurableObjectNamespace]") {
528
+ if (!isDurableObjectNamespace(bindingValue)) {
525
529
  return new Response("Invalid binding", { status: 500 });
526
530
  }
527
531
  const namespace = bindingValue;
@@ -529,24 +533,24 @@ data: ${JSON.stringify(result.data)}
529
533
  const acceptHeader = request.headers.get("accept");
530
534
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
531
535
  const body2 = JSON.stringify({
532
- jsonrpc: "2.0",
533
536
  error: {
534
537
  code: -32e3,
535
538
  message: "Not Acceptable: Client must accept both application/json and text/event-stream"
536
539
  },
537
- id: null
540
+ id: null,
541
+ jsonrpc: "2.0"
538
542
  });
539
543
  return new Response(body2, { status: 406 });
540
544
  }
541
545
  const ct = request.headers.get("content-type");
542
546
  if (!ct || !ct.includes("application/json")) {
543
547
  const body2 = JSON.stringify({
544
- jsonrpc: "2.0",
545
548
  error: {
546
549
  code: -32e3,
547
550
  message: "Unsupported Media Type: Content-Type must be application/json"
548
551
  },
549
- id: null
552
+ id: null,
553
+ jsonrpc: "2.0"
550
554
  });
551
555
  return new Response(body2, { status: 415 });
552
556
  }
@@ -556,12 +560,12 @@ data: ${JSON.stringify(result.data)}
556
560
  );
557
561
  if (contentLength > MAXIMUM_MESSAGE_SIZE_BYTES) {
558
562
  const body2 = JSON.stringify({
559
- jsonrpc: "2.0",
560
563
  error: {
561
564
  code: -32e3,
562
565
  message: `Request body too large. Maximum size is ${MAXIMUM_MESSAGE_SIZE_BYTES} bytes`
563
566
  },
564
- id: null
567
+ id: null,
568
+ jsonrpc: "2.0"
565
569
  });
566
570
  return new Response(body2, { status: 413 });
567
571
  }
@@ -569,14 +573,14 @@ data: ${JSON.stringify(result.data)}
569
573
  let rawMessage;
570
574
  try {
571
575
  rawMessage = await request.json();
572
- } catch (error) {
576
+ } catch (_error) {
573
577
  const body2 = JSON.stringify({
574
- jsonrpc: "2.0",
575
578
  error: {
576
579
  code: -32700,
577
580
  message: "Parse error: Invalid JSON"
578
581
  },
579
- id: null
582
+ id: null,
583
+ jsonrpc: "2.0"
580
584
  });
581
585
  return new Response(body2, { status: 400 });
582
586
  }
@@ -590,12 +594,12 @@ data: ${JSON.stringify(result.data)}
590
594
  for (const msg of arrayMessage) {
591
595
  if (!JSONRPCMessageSchema.safeParse(msg).success) {
592
596
  const body2 = JSON.stringify({
593
- jsonrpc: "2.0",
594
597
  error: {
595
598
  code: -32700,
596
599
  message: "Parse error: Invalid JSON-RPC message"
597
600
  },
598
- id: null
601
+ id: null,
602
+ jsonrpc: "2.0"
599
603
  });
600
604
  return new Response(body2, { status: 400 });
601
605
  }
@@ -606,34 +610,34 @@ data: ${JSON.stringify(result.data)}
606
610
  );
607
611
  if (isInitializationRequest && sessionId) {
608
612
  const body2 = JSON.stringify({
609
- jsonrpc: "2.0",
610
613
  error: {
611
614
  code: -32600,
612
615
  message: "Invalid Request: Initialization requests must not include a sessionId"
613
616
  },
614
- id: null
617
+ id: null,
618
+ jsonrpc: "2.0"
615
619
  });
616
620
  return new Response(body2, { status: 400 });
617
621
  }
618
622
  if (isInitializationRequest && messages.length > 1) {
619
623
  const body2 = JSON.stringify({
620
- jsonrpc: "2.0",
621
624
  error: {
622
625
  code: -32600,
623
626
  message: "Invalid Request: Only one initialization request is allowed"
624
627
  },
625
- id: null
628
+ id: null,
629
+ jsonrpc: "2.0"
626
630
  });
627
631
  return new Response(body2, { status: 400 });
628
632
  }
629
633
  if (!isInitializationRequest && !sessionId) {
630
634
  const body2 = JSON.stringify({
631
- jsonrpc: "2.0",
632
635
  error: {
633
636
  code: -32e3,
634
637
  message: "Bad Request: Mcp-Session-Id header is required"
635
638
  },
636
- id: null
639
+ id: null,
640
+ jsonrpc: "2.0"
637
641
  });
638
642
  return new Response(body2, { status: 400 });
639
643
  }
@@ -646,12 +650,12 @@ data: ${JSON.stringify(result.data)}
646
650
  await doStub.setInitialized();
647
651
  } else if (!isInitialized) {
648
652
  const body2 = JSON.stringify({
649
- jsonrpc: "2.0",
650
653
  error: {
651
654
  code: -32001,
652
655
  message: "Session not found"
653
656
  },
654
- id: null
657
+ id: null,
658
+ jsonrpc: "2.0"
655
659
  });
656
660
  return new Response(body2, { status: 404 });
657
661
  }
@@ -674,12 +678,12 @@ data: ${JSON.stringify(result.data)}
674
678
  console.error("Failed to establish WebSocket connection");
675
679
  await writer.close();
676
680
  const body2 = JSON.stringify({
677
- jsonrpc: "2.0",
678
681
  error: {
679
682
  code: -32001,
680
683
  message: "Failed to establish WebSocket connection"
681
684
  },
682
- id: null
685
+ id: null,
686
+ jsonrpc: "2.0"
683
687
  });
684
688
  return new Response(body2, { status: 500 });
685
689
  }
@@ -712,10 +716,10 @@ data: ${JSON.stringify(result.data)}
712
716
  onMessage(event).catch(console.error);
713
717
  });
714
718
  ws.addEventListener("error", (error) => {
715
- async function onError(error2) {
719
+ async function onError(_error) {
716
720
  try {
717
721
  await writer.close();
718
- } catch (e) {
722
+ } catch (_e) {
719
723
  }
720
724
  }
721
725
  onError(error).catch(console.error);
@@ -739,8 +743,8 @@ data: ${JSON.stringify(result.data)}
739
743
  }
740
744
  ws.close();
741
745
  return new Response(null, {
742
- status: 202,
743
- headers: corsHeaders(request, corsOptions)
746
+ headers: corsHeaders(request, corsOptions),
747
+ status: 202
744
748
  });
745
749
  }
746
750
  for (const message of messages) {
@@ -751,9 +755,9 @@ data: ${JSON.stringify(result.data)}
751
755
  }
752
756
  return new Response(readable, {
753
757
  headers: {
754
- "Content-Type": "text/event-stream",
755
758
  "Cache-Control": "no-cache",
756
759
  Connection: "keep-alive",
760
+ "Content-Type": "text/event-stream",
757
761
  "mcp-session-id": sessionId,
758
762
  ...corsHeaders(request, corsOptions)
759
763
  },
@@ -761,12 +765,12 @@ data: ${JSON.stringify(result.data)}
761
765
  });
762
766
  }
763
767
  const body = JSON.stringify({
764
- jsonrpc: "2.0",
765
768
  error: {
766
769
  code: -32e3,
767
770
  message: "Method not allowed"
768
771
  },
769
- id: null
772
+ id: null,
773
+ jsonrpc: "2.0"
770
774
  });
771
775
  return new Response(body, { status: 405 });
772
776
  }