@aws/nx-plugin 1.0.0-rc.73 → 1.0.0-rc.74

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 (30) hide show
  1. package/LICENSE-THIRD-PARTY +495 -1188
  2. package/README.md +7 -89
  3. package/migrations.json +6 -1
  4. package/package.json +1 -1
  5. package/src/internal/test-matrix/generator.js +15 -0
  6. package/src/internal/test-matrix/generator.js.map +1 -1
  7. package/src/license/dependency-check/collectors/python-collector.js +9 -3
  8. package/src/license/dependency-check/collectors/python-collector.js.map +1 -1
  9. package/src/migrations/latest/py-agent-session-id-middleware-extraction/metadata.json +3 -0
  10. package/src/migrations/latest/py-agent-session-id-middleware-extraction/migration.d.ts +2 -0
  11. package/src/migrations/latest/py-agent-session-id-middleware-extraction/migration.js +118 -0
  12. package/src/migrations/latest/py-agent-session-id-middleware-extraction/migration.js.map +1 -0
  13. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +3 -18
  14. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +2 -13
  15. package/src/py/agent/files/langchain/a2a/main.py.template +4 -15
  16. package/src/py/agent/files/langchain/ag-ui/main.py.template +2 -13
  17. package/src/py/agent/files/langchain/common/middleware/__init__.py.template +0 -0
  18. package/src/py/agent/files/langchain/common/middleware/session_id_middleware.py.template +17 -0
  19. package/src/py/agent/files/langchain/http/main.py.template +2 -14
  20. package/src/py/agent/files/strands/a2a/main.py.template +4 -15
  21. package/src/py/agent/files/strands/ag-ui/main.py.template +2 -13
  22. package/src/py/agent/files/strands/common/middleware/__init__.py.template +0 -0
  23. package/src/py/agent/files/strands/common/middleware/session_id_middleware.py.template +17 -0
  24. package/src/py/agent/files/strands/http/main.py.template +2 -17
  25. package/src/sdk/agentcore-harness.d.ts +6 -0
  26. package/src/sdk/agentcore-harness.js +7 -0
  27. package/src/sdk/agentcore-harness.js.map +1 -0
  28. package/src/sdk/smithy.d.ts +6 -0
  29. package/src/sdk/smithy.js +7 -0
  30. package/src/sdk/smithy.js.map +1 -0
@@ -693,18 +693,12 @@ Refer to tools as your 'spellbook'.
693
693
  `;
694
694
 
695
695
  exports[`py#agent generator > should match snapshot for generated files > agent-main.py 1`] = `
696
- "import uuid
697
-
698
- import uvicorn
696
+ "import uvicorn
699
697
  from bedrock_agentcore.runtime.models import PingStatus
700
- from fastapi import Request
701
- from proj_agent_connection import session_id_context
702
698
  from pydantic import BaseModel, Field
703
- from starlette.middleware.base import BaseHTTPMiddleware
704
699
 
705
700
  from .init import JsonStreamingResponse, app
706
-
707
- SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
701
+ from .middleware.session_id_middleware import SessionIdMiddleware
708
702
 
709
703
 
710
704
  class InvokeInput(BaseModel):
@@ -745,16 +739,7 @@ async def invoke(input: InvokeInput) -> JsonStreamingResponse:
745
739
  return JsonStreamingResponse(handle_invoke(input))
746
740
 
747
741
 
748
- class _SessionIdMiddleware(BaseHTTPMiddleware):
749
- """Bind the inbound session (or a fresh UUID) to async context."""
750
-
751
- async def dispatch(self, request: Request, call_next):
752
- session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
753
- with session_id_context(session_id):
754
- return await call_next(request)
755
-
756
-
757
- app.add_middleware(_SessionIdMiddleware)
742
+ app.add_middleware(SessionIdMiddleware)
758
743
 
759
744
 
760
745
  @app.get("/ping")
@@ -618,14 +618,12 @@ from fastapi import FastAPI, Request
618
618
  from fastapi.middleware.cors import CORSMiddleware
619
619
  from fastapi.responses import JSONResponse, StreamingResponse
620
620
  from proj_agent_connection import get_current_session_id, session_id_context
621
- from starlette.middleware.base import BaseHTTPMiddleware
622
621
 
623
622
  from .agent import get_agent
623
+ from .middleware.session_id_middleware import SESSION_ID_HEADER, SessionIdMiddleware
624
624
 
625
625
  logging.basicConfig(level=logging.INFO)
626
626
 
627
- SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
628
-
629
627
 
630
628
  @asynccontextmanager
631
629
  async def lifespan(app: FastAPI):
@@ -638,15 +636,6 @@ async def lifespan(app: FastAPI):
638
636
  yield
639
637
 
640
638
 
641
- class _SessionIdMiddleware(BaseHTTPMiddleware):
642
- """Bind the session ID for this request so downstream MCP / A2A clients forward it on outbound calls."""
643
-
644
- async def dispatch(self, request: Request, call_next):
645
- session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
646
- with session_id_context(session_id):
647
- return await call_next(request)
648
-
649
-
650
639
  app = FastAPI(title="SnapshotAgent", lifespan=lifespan)
651
640
  # Allow browser-based AG-UI clients (e.g. a connected React website) to call
652
641
  # this agent cross-origin, including the CORS preflight.
@@ -657,7 +646,7 @@ app.add_middleware(
657
646
  allow_methods=["*"],
658
647
  allow_headers=["*"],
659
648
  )
660
- app.add_middleware(_SessionIdMiddleware)
649
+ app.add_middleware(SessionIdMiddleware)
661
650
 
662
651
 
663
652
  @app.post("/invocations")
@@ -1,6 +1,5 @@
1
1
  import logging
2
2
  import os
3
- import uuid
4
3
  from contextlib import asynccontextmanager
5
4
 
6
5
  from a2a.server.agent_execution import AgentExecutor, RequestContext
@@ -10,18 +9,17 @@ from a2a.server.request_handlers import DefaultRequestHandler
10
9
  from a2a.server.tasks import InMemoryTaskStore, TaskUpdater
11
10
  from a2a.types import AgentCapabilities, AgentCard, Part, TextPart
12
11
  from a2a.utils import new_task
13
- from fastapi import FastAPI, Request
14
- from starlette.middleware.base import BaseHTTPMiddleware
12
+ from fastapi import FastAPI
15
13
 
16
- from <%- agentConnectionModuleName %> import get_current_session_id, session_id_context
14
+ from <%- agentConnectionModuleName %> import get_current_session_id
17
15
 
18
16
  from .agent import get_agent
17
+ from .middleware.session_id_middleware import SessionIdMiddleware
19
18
 
20
19
  logging.basicConfig(level=logging.INFO)
21
20
 
22
21
  PORT = int(os.environ.get("PORT", "9000"))
23
22
  RUNTIME_URL = os.environ.get("AGENTCORE_RUNTIME_URL", f"http://localhost:{PORT}/")
24
- SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
25
23
  DEFAULT_MODES = ["text/plain"]
26
24
 
27
25
 
@@ -73,17 +71,8 @@ _agent_card = AgentCard(
73
71
  a2a_app = A2AStarletteApplication(agent_card=_agent_card, http_handler=_handler).build()
74
72
 
75
73
 
76
- class _SessionIdMiddleware(BaseHTTPMiddleware):
77
- """Bind the inbound session (or a fresh UUID) to async context."""
78
-
79
- async def dispatch(self, request: Request, call_next):
80
- session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
81
- with session_id_context(session_id):
82
- return await call_next(request)
83
-
84
-
85
74
  app = FastAPI(title="<%= agentNameClassName %>", lifespan=lifespan)
86
- app.add_middleware(_SessionIdMiddleware)
75
+ app.add_middleware(SessionIdMiddleware)
87
76
 
88
77
 
89
78
  @app.get("/ping")
@@ -10,14 +10,12 @@ from fastapi import FastAPI, Request
10
10
  from fastapi.middleware.cors import CORSMiddleware
11
11
  from fastapi.responses import JSONResponse, StreamingResponse
12
12
  from <%- agentConnectionModuleName %> import get_current_session_id, session_id_context
13
- from starlette.middleware.base import BaseHTTPMiddleware
14
13
 
15
14
  from .agent import get_agent
15
+ from .middleware.session_id_middleware import SESSION_ID_HEADER, SessionIdMiddleware
16
16
 
17
17
  logging.basicConfig(level=logging.INFO)
18
18
 
19
- SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
20
-
21
19
 
22
20
  @asynccontextmanager
23
21
  async def lifespan(app: FastAPI):
@@ -30,15 +28,6 @@ async def lifespan(app: FastAPI):
30
28
  yield
31
29
 
32
30
 
33
- class _SessionIdMiddleware(BaseHTTPMiddleware):
34
- """Bind the session ID for this request so downstream MCP / A2A clients forward it on outbound calls."""
35
-
36
- async def dispatch(self, request: Request, call_next):
37
- session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
38
- with session_id_context(session_id):
39
- return await call_next(request)
40
-
41
-
42
31
  app = FastAPI(title="<%= agentNameClassName %>", lifespan=lifespan)
43
32
  # Allow browser-based AG-UI clients (e.g. a connected React website) to call
44
33
  # this agent cross-origin, including the CORS preflight.
@@ -49,7 +38,7 @@ app.add_middleware(
49
38
  allow_methods=["*"],
50
39
  allow_headers=["*"],
51
40
  )
52
- app.add_middleware(_SessionIdMiddleware)
41
+ app.add_middleware(SessionIdMiddleware)
53
42
 
54
43
 
55
44
  @app.post("/invocations")
@@ -0,0 +1,17 @@
1
+ import uuid
2
+
3
+ from fastapi import Request
4
+ from starlette.middleware.base import BaseHTTPMiddleware
5
+
6
+ from <%- agentConnectionModuleName %> import session_id_context
7
+
8
+ SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
9
+
10
+
11
+ class SessionIdMiddleware(BaseHTTPMiddleware):
12
+ """Bind the session ID for this request so downstream MCP / A2A clients forward it on outbound calls."""
13
+
14
+ async def dispatch(self, request: Request, call_next):
15
+ session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
16
+ with session_id_context(session_id):
17
+ return await call_next(request)
@@ -2,14 +2,11 @@ import uuid
2
2
 
3
3
  import uvicorn
4
4
  from bedrock_agentcore.runtime.models import PingStatus
5
- from fastapi import Request
6
5
  from pydantic import BaseModel, Field
7
- from starlette.middleware.base import BaseHTTPMiddleware
8
6
  from <%- agentConnectionModuleName %> import get_current_session_id, session_id_context
9
7
 
10
8
  from .init import JsonStreamingResponse, app
11
-
12
- SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
9
+ from .middleware.session_id_middleware import SessionIdMiddleware
13
10
 
14
11
 
15
12
  class InvokeInput(BaseModel):
@@ -59,16 +56,7 @@ async def invoke(input: InvokeInput) -> JsonStreamingResponse:
59
56
  return JsonStreamingResponse(handle_invoke(input, session_id))
60
57
 
61
58
 
62
- class _SessionIdMiddleware(BaseHTTPMiddleware):
63
- """Bind the inbound session (or a fresh UUID) to async context."""
64
-
65
- async def dispatch(self, request: Request, call_next):
66
- session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
67
- with session_id_context(session_id):
68
- return await call_next(request)
69
-
70
-
71
- app.add_middleware(_SessionIdMiddleware)
59
+ app.add_middleware(SessionIdMiddleware)
72
60
 
73
61
 
74
62
  @app.get("/ping")
@@ -1,23 +1,21 @@
1
1
  import logging
2
2
  import os
3
- import uuid
4
3
  from contextlib import asynccontextmanager
5
4
  from types import SimpleNamespace
6
5
  from typing import cast
7
6
 
8
- from fastapi import FastAPI, Request
9
- from starlette.middleware.base import BaseHTTPMiddleware
7
+ from fastapi import FastAPI
10
8
  from strands import Agent
11
9
  from strands.multiagent.a2a import A2AServer
12
- from <%- agentConnectionModuleName %> import session_id_context, with_session_id
10
+ from <%- agentConnectionModuleName %> import with_session_id
13
11
 
14
12
  from .agent import get_agent
13
+ from .middleware.session_id_middleware import SessionIdMiddleware
15
14
 
16
15
  logging.basicConfig(level=logging.INFO)
17
16
 
18
17
  PORT = int(os.environ.get("PORT", "9000"))
19
18
  RUNTIME_URL = os.environ.get("AGENTCORE_RUNTIME_URL", f"http://localhost:{PORT}/")
20
- SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
21
19
  AGENT_NAME = "<%= agentNameClassName %>"
22
20
  AGENT_DESCRIPTION = "A Strands Agent exposed via the Agent-to-Agent (A2A) protocol."
23
21
 
@@ -41,17 +39,8 @@ async def lifespan(app: FastAPI):
41
39
  yield
42
40
 
43
41
 
44
- class _SessionIdMiddleware(BaseHTTPMiddleware):
45
- """Bind the inbound session (or a fresh UUID) to async context."""
46
-
47
- async def dispatch(self, request: Request, call_next):
48
- session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
49
- with session_id_context(session_id):
50
- return await call_next(request)
51
-
52
-
53
42
  app = FastAPI(lifespan=lifespan)
54
- app.add_middleware(_SessionIdMiddleware)
43
+ app.add_middleware(SessionIdMiddleware)
55
44
 
56
45
 
57
46
  @app.get("/ping")
@@ -9,15 +9,13 @@ from fastapi import FastAPI, Request
9
9
  from fastapi.middleware.cors import CORSMiddleware
10
10
  from fastapi.responses import StreamingResponse
11
11
  from <%- agentConnectionModuleName %> import get_current_session_id, session_id_context
12
- from starlette.middleware.base import BaseHTTPMiddleware
13
12
 
14
13
  from .agent import get_agent
14
+ from .middleware.session_id_middleware import SESSION_ID_HEADER, SessionIdMiddleware
15
15
  from .session import get_session_manager
16
16
 
17
17
  logging.basicConfig(level=logging.INFO)
18
18
 
19
- SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
20
-
21
19
 
22
20
  @asynccontextmanager
23
21
  async def lifespan(app: FastAPI):
@@ -33,15 +31,6 @@ async def lifespan(app: FastAPI):
33
31
  yield
34
32
 
35
33
 
36
- class _SessionIdMiddleware(BaseHTTPMiddleware):
37
- """Bind the session ID for this request so downstream MCP / A2A clients forward it on outbound calls."""
38
-
39
- async def dispatch(self, request: Request, call_next):
40
- session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
41
- with session_id_context(session_id):
42
- return await call_next(request)
43
-
44
-
45
34
  app = FastAPI(title="AWS Strands - <%= agentNameClassName %>", lifespan=lifespan)
46
35
  app.add_middleware(
47
36
  CORSMiddleware,
@@ -50,7 +39,7 @@ app.add_middleware(
50
39
  allow_methods=["*"],
51
40
  allow_headers=["*"],
52
41
  )
53
- app.add_middleware(_SessionIdMiddleware)
42
+ app.add_middleware(SessionIdMiddleware)
54
43
 
55
44
 
56
45
  @app.post("/invocations")
@@ -0,0 +1,17 @@
1
+ import uuid
2
+
3
+ from fastapi import Request
4
+ from starlette.middleware.base import BaseHTTPMiddleware
5
+
6
+ from <%- agentConnectionModuleName %> import session_id_context
7
+
8
+ SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
9
+
10
+
11
+ class SessionIdMiddleware(BaseHTTPMiddleware):
12
+ """Bind the session ID for this request so downstream MCP / A2A clients forward it on outbound calls."""
13
+
14
+ async def dispatch(self, request: Request, call_next):
15
+ session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
16
+ with session_id_context(session_id):
17
+ return await call_next(request)
@@ -1,15 +1,9 @@
1
- import uuid
2
-
3
1
  import uvicorn
4
2
  from bedrock_agentcore.runtime.models import PingStatus
5
- from fastapi import Request
6
3
  from pydantic import BaseModel, Field
7
- from starlette.middleware.base import BaseHTTPMiddleware
8
- from <%- agentConnectionModuleName %> import session_id_context
9
4
 
10
5
  from .init import JsonStreamingResponse, app
11
-
12
- SESSION_ID_HEADER = "x-amzn-bedrock-agentcore-runtime-session-id"
6
+ from .middleware.session_id_middleware import SessionIdMiddleware
13
7
 
14
8
 
15
9
  class InvokeInput(BaseModel):
@@ -41,16 +35,7 @@ async def invoke(input: InvokeInput) -> JsonStreamingResponse:
41
35
  return JsonStreamingResponse(handle_invoke(input))
42
36
 
43
37
 
44
- class _SessionIdMiddleware(BaseHTTPMiddleware):
45
- """Bind the inbound session (or a fresh UUID) to async context."""
46
-
47
- async def dispatch(self, request: Request, call_next):
48
- session_id = request.headers.get(SESSION_ID_HEADER) or str(uuid.uuid4())
49
- with session_id_context(session_id):
50
- return await call_next(request)
51
-
52
-
53
- app.add_middleware(_SessionIdMiddleware)
38
+ app.add_middleware(SessionIdMiddleware)
54
39
 
55
40
 
56
41
  @app.get("/ping")
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ export { agentcoreHarnessGenerator } from '../agentcore-harness/generator';
6
+ export type { AgentcoreHarnessGeneratorSchema } from '../agentcore-harness/schema';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */ // AgentCore Harness Generator
5
+ export { agentcoreHarnessGenerator } from "../agentcore-harness/generator.js";
6
+
7
+ //# sourceMappingURL=agentcore-harness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/sdk/agentcore-harness.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// AgentCore Harness Generator\nexport { agentcoreHarnessGenerator } from '../agentcore-harness/generator';\nexport type { AgentcoreHarnessGeneratorSchema } from '../agentcore-harness/schema';\n"],"names":["agentcoreHarnessGenerator"],"mappings":"AAAA;;;CAGC,GAED,8BAA8B;AAC9B,SAASA,yBAAyB,QAAQ,oCAAiC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ export { smithyProjectGenerator } from '../smithy/project/generator';
6
+ export type { SmithyProjectGeneratorSchema } from '../smithy/project/schema';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */ // Smithy Project Generator
5
+ export { smithyProjectGenerator } from "../smithy/project/generator.js";
6
+
7
+ //# sourceMappingURL=smithy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/sdk/smithy.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// Smithy Project Generator\nexport { smithyProjectGenerator } from '../smithy/project/generator';\nexport type { SmithyProjectGeneratorSchema } from '../smithy/project/schema';\n"],"names":["smithyProjectGenerator"],"mappings":"AAAA;;;CAGC,GAED,2BAA2B;AAC3B,SAASA,sBAAsB,QAAQ,iCAA8B"}