bedrock-agentcore 0.0.1 → 0.2.0
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/LICENSE +202 -0
- package/README.md +131 -9
- package/dist/src/_utils/endpoints.d.ts +28 -0
- package/dist/src/_utils/endpoints.d.ts.map +1 -0
- package/dist/src/_utils/endpoints.js +44 -0
- package/dist/src/_utils/endpoints.js.map +1 -0
- package/dist/src/identity/client.d.ts +40 -0
- package/dist/src/identity/client.d.ts.map +1 -0
- package/dist/src/identity/client.js +109 -0
- package/dist/src/identity/client.js.map +1 -0
- package/dist/src/identity/index.d.ts +22 -0
- package/dist/src/identity/index.d.ts.map +1 -0
- package/dist/src/identity/index.js +24 -0
- package/dist/src/identity/index.js.map +1 -0
- package/dist/src/identity/types.d.ts +82 -0
- package/dist/src/identity/types.d.ts.map +1 -0
- package/dist/src/identity/types.js +5 -0
- package/dist/src/identity/types.js.map +1 -0
- package/dist/src/identity/wrappers.d.ts +54 -0
- package/dist/src/identity/wrappers.d.ts.map +1 -0
- package/dist/src/identity/wrappers.js +95 -0
- package/dist/src/identity/wrappers.js.map +1 -0
- package/dist/src/runtime/app.d.ts +144 -0
- package/dist/src/runtime/app.d.ts.map +1 -0
- package/dist/src/runtime/app.js +485 -0
- package/dist/src/runtime/app.js.map +1 -0
- package/dist/src/runtime/client.d.ts +154 -0
- package/dist/src/runtime/client.d.ts.map +1 -0
- package/dist/src/runtime/client.js +319 -0
- package/dist/src/runtime/client.js.map +1 -0
- package/dist/src/runtime/context.d.ts +33 -0
- package/dist/src/runtime/context.d.ts.map +1 -0
- package/dist/src/runtime/context.js +49 -0
- package/dist/src/runtime/context.js.map +1 -0
- package/dist/src/runtime/index.d.ts +8 -0
- package/dist/src/runtime/index.d.ts.map +1 -0
- package/dist/src/runtime/index.js +7 -0
- package/dist/src/runtime/index.js.map +1 -0
- package/dist/src/runtime/types.d.ts +429 -0
- package/dist/src/runtime/types.d.ts.map +1 -0
- package/dist/src/runtime/types.js +26 -0
- package/dist/src/runtime/types.js.map +1 -0
- package/dist/src/tools/browser/client.d.ts +125 -0
- package/dist/src/tools/browser/client.d.ts.map +1 -0
- package/dist/src/tools/browser/client.js +320 -0
- package/dist/src/tools/browser/client.js.map +1 -0
- package/dist/src/tools/browser/index.d.ts +4 -0
- package/dist/src/tools/browser/index.d.ts.map +1 -0
- package/dist/src/tools/browser/index.js +3 -0
- package/dist/src/tools/browser/index.js.map +1 -0
- package/dist/src/tools/browser/integrations/playwright/client.d.ts +147 -0
- package/dist/src/tools/browser/integrations/playwright/client.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/playwright/client.js +324 -0
- package/dist/src/tools/browser/integrations/playwright/client.js.map +1 -0
- package/dist/src/tools/browser/integrations/playwright/index.d.ts +20 -0
- package/dist/src/tools/browser/integrations/playwright/index.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/playwright/index.js +19 -0
- package/dist/src/tools/browser/integrations/playwright/index.js.map +1 -0
- package/dist/src/tools/browser/integrations/playwright/types.d.ts +169 -0
- package/dist/src/tools/browser/integrations/playwright/types.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/playwright/types.js +2 -0
- package/dist/src/tools/browser/integrations/playwright/types.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/click-tool.d.ts +20 -0
- package/dist/src/tools/browser/integrations/strands/click-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/click-tool.js +33 -0
- package/dist/src/tools/browser/integrations/strands/click-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/evaluate-tool.d.ts +20 -0
- package/dist/src/tools/browser/integrations/strands/evaluate-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/evaluate-tool.js +34 -0
- package/dist/src/tools/browser/integrations/strands/evaluate-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/get-html-tool.d.ts +19 -0
- package/dist/src/tools/browser/integrations/strands/get-html-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/get-html-tool.js +32 -0
- package/dist/src/tools/browser/integrations/strands/get-html-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/get-text-tool.d.ts +19 -0
- package/dist/src/tools/browser/integrations/strands/get-text-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/get-text-tool.js +32 -0
- package/dist/src/tools/browser/integrations/strands/get-text-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/index.d.ts +25 -0
- package/dist/src/tools/browser/integrations/strands/index.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/index.js +25 -0
- package/dist/src/tools/browser/integrations/strands/index.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/navigate-tool.d.ts +21 -0
- package/dist/src/tools/browser/integrations/strands/navigate-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/navigate-tool.js +41 -0
- package/dist/src/tools/browser/integrations/strands/navigate-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/screenshot-tool.d.ts +29 -0
- package/dist/src/tools/browser/integrations/strands/screenshot-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/screenshot-tool.js +52 -0
- package/dist/src/tools/browser/integrations/strands/screenshot-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/tools.d.ts +119 -0
- package/dist/src/tools/browser/integrations/strands/tools.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/tools.js +141 -0
- package/dist/src/tools/browser/integrations/strands/tools.js.map +1 -0
- package/dist/src/tools/browser/integrations/strands/type-tool.d.ts +22 -0
- package/dist/src/tools/browser/integrations/strands/type-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/strands/type-tool.js +37 -0
- package/dist/src/tools/browser/integrations/strands/type-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/click-tool.d.ts +18 -0
- package/dist/src/tools/browser/integrations/vercel-ai/click-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/click-tool.js +31 -0
- package/dist/src/tools/browser/integrations/vercel-ai/click-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/evaluate-tool.d.ts +18 -0
- package/dist/src/tools/browser/integrations/vercel-ai/evaluate-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/evaluate-tool.js +32 -0
- package/dist/src/tools/browser/integrations/vercel-ai/evaluate-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/get-html-tool.d.ts +17 -0
- package/dist/src/tools/browser/integrations/vercel-ai/get-html-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/get-html-tool.js +30 -0
- package/dist/src/tools/browser/integrations/vercel-ai/get-html-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/get-text-tool.d.ts +17 -0
- package/dist/src/tools/browser/integrations/vercel-ai/get-text-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/get-text-tool.js +30 -0
- package/dist/src/tools/browser/integrations/vercel-ai/get-text-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/index.d.ts +19 -0
- package/dist/src/tools/browser/integrations/vercel-ai/index.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/index.js +19 -0
- package/dist/src/tools/browser/integrations/vercel-ai/index.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/navigate-tool.d.ts +19 -0
- package/dist/src/tools/browser/integrations/vercel-ai/navigate-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/navigate-tool.js +39 -0
- package/dist/src/tools/browser/integrations/vercel-ai/navigate-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/screenshot-tool.d.ts +22 -0
- package/dist/src/tools/browser/integrations/vercel-ai/screenshot-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/screenshot-tool.js +44 -0
- package/dist/src/tools/browser/integrations/vercel-ai/screenshot-tool.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/tools.d.ts +123 -0
- package/dist/src/tools/browser/integrations/vercel-ai/tools.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/tools.js +145 -0
- package/dist/src/tools/browser/integrations/vercel-ai/tools.js.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/type-tool.d.ts +20 -0
- package/dist/src/tools/browser/integrations/vercel-ai/type-tool.d.ts.map +1 -0
- package/dist/src/tools/browser/integrations/vercel-ai/type-tool.js +35 -0
- package/dist/src/tools/browser/integrations/vercel-ai/type-tool.js.map +1 -0
- package/dist/src/tools/browser/types.d.ts +336 -0
- package/dist/src/tools/browser/types.d.ts.map +1 -0
- package/dist/src/tools/browser/types.js +17 -0
- package/dist/src/tools/browser/types.js.map +1 -0
- package/dist/src/tools/code-interpreter/client.d.ts +214 -0
- package/dist/src/tools/code-interpreter/client.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/client.js +518 -0
- package/dist/src/tools/code-interpreter/client.js.map +1 -0
- package/dist/src/tools/code-interpreter/index.d.ts +4 -0
- package/dist/src/tools/code-interpreter/index.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/index.js +5 -0
- package/dist/src/tools/code-interpreter/index.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/execute-code-tool.d.ts +28 -0
- package/dist/src/tools/code-interpreter/integrations/strands/execute-code-tool.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/execute-code-tool.js +47 -0
- package/dist/src/tools/code-interpreter/integrations/strands/execute-code-tool.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/execute-command-tool.d.ts +27 -0
- package/dist/src/tools/code-interpreter/integrations/strands/execute-command-tool.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/execute-command-tool.js +42 -0
- package/dist/src/tools/code-interpreter/integrations/strands/execute-command-tool.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/file-operations-tool.d.ts +33 -0
- package/dist/src/tools/code-interpreter/integrations/strands/file-operations-tool.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/file-operations-tool.js +78 -0
- package/dist/src/tools/code-interpreter/integrations/strands/file-operations-tool.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/index.d.ts +32 -0
- package/dist/src/tools/code-interpreter/integrations/strands/index.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/index.js +32 -0
- package/dist/src/tools/code-interpreter/integrations/strands/index.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/tools.d.ts +94 -0
- package/dist/src/tools/code-interpreter/integrations/strands/tools.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/strands/tools.js +112 -0
- package/dist/src/tools/code-interpreter/integrations/strands/tools.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-code-tool.d.ts +27 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-code-tool.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-code-tool.js +46 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-code-tool.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-command-tool.d.ts +26 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-command-tool.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-command-tool.js +41 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-command-tool.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/file-operations-tool.d.ts +32 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/file-operations-tool.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/file-operations-tool.js +77 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/file-operations-tool.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/index.d.ts +26 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/index.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/index.js +26 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/index.js.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/tools.d.ts +94 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/tools.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/tools.js +112 -0
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/tools.js.map +1 -0
- package/dist/src/tools/code-interpreter/types.d.ts +473 -0
- package/dist/src/tools/code-interpreter/types.d.ts.map +1 -0
- package/dist/src/tools/code-interpreter/types.js +52 -0
- package/dist/src/tools/code-interpreter/types.js.map +1 -0
- package/package.json +134 -12
- package/index.js +0 -4
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { defaultProvider } from '@aws-sdk/credential-provider-node';
|
|
2
|
+
import { HttpRequest } from '@aws-sdk/protocol-http';
|
|
3
|
+
import { SignatureV4 } from '@aws-sdk/signature-v4';
|
|
4
|
+
import { Sha256 } from '@aws-crypto/sha256-js';
|
|
5
|
+
import { randomUUID, randomBytes } from 'crypto';
|
|
6
|
+
import { getDataPlaneEndpoint } from '../_utils/endpoints.js';
|
|
7
|
+
import { DEFAULT_PRESIGNED_URL_TIMEOUT, MAX_PRESIGNED_URL_TIMEOUT } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Client for generating WebSocket authentication for AgentCore Runtime.
|
|
10
|
+
*
|
|
11
|
+
* This client provides authentication credentials for WebSocket connections
|
|
12
|
+
* to AgentCore Runtime endpoints, allowing applications to establish
|
|
13
|
+
* bidirectional streaming connections with agent runtimes.
|
|
14
|
+
*
|
|
15
|
+
* The client is stateless and does not manage session lifecycle. Each method
|
|
16
|
+
* call is independent and takes the runtime ARN as a parameter.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const client = new RuntimeClient({ region: 'us-west-2' })
|
|
21
|
+
*
|
|
22
|
+
* // Generate WebSocket connection with SigV4 headers
|
|
23
|
+
* const { url, headers } = await client.generateWsConnection({
|
|
24
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-runtime',
|
|
25
|
+
* endpointName: 'DEFAULT'
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // Generate presigned WebSocket URL
|
|
29
|
+
* const presignedUrl = await client.generatePresignedUrl({
|
|
30
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-runtime',
|
|
31
|
+
* expires: 300
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class RuntimeClient {
|
|
36
|
+
region;
|
|
37
|
+
credentialsProvider;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new RuntimeClient instance.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Configuration options for the client
|
|
42
|
+
* @throws Error if region is not provided via config or AWS_REGION environment variable
|
|
43
|
+
*/
|
|
44
|
+
constructor(config = {}) {
|
|
45
|
+
const region = config.region ?? process.env.AWS_REGION;
|
|
46
|
+
if (!region || !region.trim()) {
|
|
47
|
+
throw new Error('Region must be provided via config.region or AWS_REGION environment variable');
|
|
48
|
+
}
|
|
49
|
+
this.region = region;
|
|
50
|
+
this.credentialsProvider = config.credentialsProvider ?? defaultProvider();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parses runtime ARN and extracts components.
|
|
54
|
+
*
|
|
55
|
+
* @param runtimeArn - Full runtime ARN
|
|
56
|
+
* @returns Parsed ARN components
|
|
57
|
+
* @throws Error if ARN format is invalid
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
_parseRuntimeArn(runtimeArn) {
|
|
62
|
+
const arnRegex = /^arn:aws:bedrock-agentcore:([^:]+):([^:]+):runtime\/(.+)$/;
|
|
63
|
+
const match = runtimeArn.match(arnRegex);
|
|
64
|
+
if (!match) {
|
|
65
|
+
throw new Error(`Invalid runtime ARN format: ${runtimeArn}`);
|
|
66
|
+
}
|
|
67
|
+
const [, region, accountId, runtimeId] = match;
|
|
68
|
+
if (!region || !accountId || !runtimeId) {
|
|
69
|
+
throw new Error('ARN components cannot be empty');
|
|
70
|
+
}
|
|
71
|
+
return { region, accountId, runtimeId };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Builds WebSocket URL with query parameters.
|
|
75
|
+
*
|
|
76
|
+
* @param runtimeArn - Full runtime ARN
|
|
77
|
+
* @param endpointName - Optional endpoint name for qualifier param
|
|
78
|
+
* @param customHeaders - Optional custom query parameters
|
|
79
|
+
* @returns WebSocket URL with query parameters
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
_buildWebSocketUrl(runtimeArn, endpointName, customHeaders) {
|
|
84
|
+
// Get the data plane endpoint and build base URL
|
|
85
|
+
const endpoint = getDataPlaneEndpoint(this.region);
|
|
86
|
+
const encodedArn = encodeURIComponent(runtimeArn);
|
|
87
|
+
const url = new URL(`${endpoint}/runtimes/${encodedArn}/ws`);
|
|
88
|
+
// Add query parameters
|
|
89
|
+
if (endpointName) {
|
|
90
|
+
url.searchParams.set('qualifier', endpointName);
|
|
91
|
+
}
|
|
92
|
+
if (customHeaders) {
|
|
93
|
+
Object.entries(customHeaders).forEach(([key, value]) => {
|
|
94
|
+
url.searchParams.set(key, value);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// Convert to WebSocket URL
|
|
98
|
+
return url.toString().replace('https://', 'wss://');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generates WebSocket URL and SigV4 signed headers for runtime connection.
|
|
102
|
+
*
|
|
103
|
+
* This method creates authentication credentials for establishing a WebSocket
|
|
104
|
+
* connection to an AgentCore Runtime. The returned headers include AWS SigV4
|
|
105
|
+
* signature for authentication.
|
|
106
|
+
*
|
|
107
|
+
* @param params - Parameters for generating the connection
|
|
108
|
+
* @returns WebSocket URL and authentication headers
|
|
109
|
+
*
|
|
110
|
+
* @throws Error if runtime ARN format is invalid
|
|
111
|
+
* @throws Error if AWS credentials are not available
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const client = new RuntimeClient({ region: 'us-west-2' })
|
|
116
|
+
*
|
|
117
|
+
* // With auto-generated session ID
|
|
118
|
+
* const { url, headers } = await client.generateWsConnection({
|
|
119
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime'
|
|
120
|
+
* })
|
|
121
|
+
*
|
|
122
|
+
* // With custom session ID and endpoint
|
|
123
|
+
* const connection = await client.generateWsConnection({
|
|
124
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime',
|
|
125
|
+
* sessionId: 'my-session-123',
|
|
126
|
+
* endpointName: 'DEFAULT'
|
|
127
|
+
* })
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
async generateWsConnection(params) {
|
|
131
|
+
this._parseRuntimeArn(params.runtimeArn);
|
|
132
|
+
const sessionId = params.sessionId ?? randomUUID();
|
|
133
|
+
const wsUrl = this._buildWebSocketUrl(params.runtimeArn, params.endpointName);
|
|
134
|
+
const credentials = await this.credentialsProvider();
|
|
135
|
+
if (!credentials) {
|
|
136
|
+
throw new Error('No AWS credentials found');
|
|
137
|
+
}
|
|
138
|
+
// Create and sign the request
|
|
139
|
+
const url = new URL(wsUrl.replace('wss://', 'https://'));
|
|
140
|
+
const signedRequest = await new SignatureV4({
|
|
141
|
+
credentials,
|
|
142
|
+
region: this.region,
|
|
143
|
+
service: 'bedrock-agentcore',
|
|
144
|
+
sha256: Sha256,
|
|
145
|
+
}).sign(new HttpRequest({
|
|
146
|
+
protocol: 'https:',
|
|
147
|
+
hostname: url.hostname,
|
|
148
|
+
path: url.pathname,
|
|
149
|
+
query: Object.fromEntries(url.searchParams.entries()),
|
|
150
|
+
method: 'GET',
|
|
151
|
+
headers: {
|
|
152
|
+
host: url.hostname,
|
|
153
|
+
'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id': sessionId,
|
|
154
|
+
},
|
|
155
|
+
}));
|
|
156
|
+
// Return WebSocket connection with signed headers + WebSocket upgrade headers
|
|
157
|
+
return {
|
|
158
|
+
url: wsUrl,
|
|
159
|
+
headers: {
|
|
160
|
+
...signedRequest.headers,
|
|
161
|
+
Connection: 'Upgrade',
|
|
162
|
+
Upgrade: 'websocket',
|
|
163
|
+
'Sec-WebSocket-Version': '13',
|
|
164
|
+
'Sec-WebSocket-Key': randomBytes(16).toString('base64'),
|
|
165
|
+
'User-Agent': 'AgentCoreRuntimeClient/1.0',
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Generates a presigned WebSocket URL for runtime connection.
|
|
171
|
+
*
|
|
172
|
+
* Presigned URLs include authentication in query parameters, allowing
|
|
173
|
+
* frontend clients to connect without managing AWS credentials.
|
|
174
|
+
*
|
|
175
|
+
* @param params - Parameters for generating the presigned URL
|
|
176
|
+
* @returns Presigned WebSocket URL with authentication in query parameters
|
|
177
|
+
*
|
|
178
|
+
* @throws Error if expires exceeds maximum (300 seconds)
|
|
179
|
+
* @throws Error if runtime ARN format is invalid
|
|
180
|
+
* @throws Error if AWS credentials are not available
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const client = new RuntimeClient({ region: 'us-west-2' })
|
|
185
|
+
*
|
|
186
|
+
* // Basic presigned URL
|
|
187
|
+
* const url = await client.generatePresignedUrl({
|
|
188
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime'
|
|
189
|
+
* })
|
|
190
|
+
*
|
|
191
|
+
* // With custom parameters
|
|
192
|
+
* const url = await client.generatePresignedUrl({
|
|
193
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime',
|
|
194
|
+
* sessionId: 'my-session-123',
|
|
195
|
+
* endpointName: 'DEFAULT',
|
|
196
|
+
* customHeaders: { 'custom-param': 'value' },
|
|
197
|
+
* expires: 300
|
|
198
|
+
* })
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
async generatePresignedUrl(params) {
|
|
202
|
+
// Validate expires parameter
|
|
203
|
+
const expires = params.expires ?? DEFAULT_PRESIGNED_URL_TIMEOUT;
|
|
204
|
+
if (expires > MAX_PRESIGNED_URL_TIMEOUT) {
|
|
205
|
+
throw new Error(`Expiry timeout cannot exceed ${MAX_PRESIGNED_URL_TIMEOUT} seconds, got ${expires}`);
|
|
206
|
+
}
|
|
207
|
+
// Validate ARN
|
|
208
|
+
this._parseRuntimeArn(params.runtimeArn);
|
|
209
|
+
// Auto-generate session ID if not provided
|
|
210
|
+
const sessionId = params.sessionId ?? randomUUID();
|
|
211
|
+
// Build minimal WebSocket URL without any custom parameters
|
|
212
|
+
// This should match the working presigned URL format
|
|
213
|
+
const wsUrl = this._buildWebSocketUrl(params.runtimeArn, params.endpointName, {
|
|
214
|
+
...params.customHeaders,
|
|
215
|
+
'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id': sessionId,
|
|
216
|
+
});
|
|
217
|
+
// Convert wss:// to https:// for signing
|
|
218
|
+
const httpsUrl = wsUrl.replace('wss://', 'https://');
|
|
219
|
+
const url = new URL(httpsUrl);
|
|
220
|
+
// Get AWS credentials
|
|
221
|
+
const credentials = await this.credentialsProvider();
|
|
222
|
+
if (!credentials) {
|
|
223
|
+
throw new Error('No AWS credentials found');
|
|
224
|
+
}
|
|
225
|
+
// Create minimal request to sign - separate path and query for presigned URLs
|
|
226
|
+
const request = new HttpRequest({
|
|
227
|
+
method: 'GET',
|
|
228
|
+
protocol: 'https:',
|
|
229
|
+
hostname: url.hostname,
|
|
230
|
+
path: url.pathname,
|
|
231
|
+
query: Object.fromEntries(url.searchParams.entries()),
|
|
232
|
+
headers: {
|
|
233
|
+
host: url.hostname,
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
// Sign the request with SigV4 (presigned URL style) following the exact pattern
|
|
237
|
+
const signer = new SignatureV4({
|
|
238
|
+
credentials,
|
|
239
|
+
region: this.region,
|
|
240
|
+
service: 'bedrock-agentcore',
|
|
241
|
+
sha256: Sha256,
|
|
242
|
+
});
|
|
243
|
+
const signedRequest = await signer.presign(request, { expiresIn: expires });
|
|
244
|
+
// Construct the full signed URL with query parameters
|
|
245
|
+
let presignedUrl = `${signedRequest.protocol}//${signedRequest.hostname}${signedRequest.path}`;
|
|
246
|
+
// Add the signature query parameters
|
|
247
|
+
if (signedRequest.query) {
|
|
248
|
+
const existingParams = presignedUrl.includes('?') ? '&' : '?';
|
|
249
|
+
const queryString = Object.entries(signedRequest.query)
|
|
250
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`)
|
|
251
|
+
.join('&');
|
|
252
|
+
presignedUrl += existingParams + queryString;
|
|
253
|
+
}
|
|
254
|
+
// Convert signed URL from https:// back to wss://
|
|
255
|
+
const presignedWsUrl = presignedUrl.replace('https://', 'wss://');
|
|
256
|
+
return presignedWsUrl;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Generates WebSocket URL and OAuth headers for runtime connection.
|
|
260
|
+
*
|
|
261
|
+
* This method uses OAuth bearer token authentication instead of AWS SigV4.
|
|
262
|
+
* Suitable for scenarios where OAuth tokens are used for authentication.
|
|
263
|
+
* Does NOT require AWS credentials.
|
|
264
|
+
*
|
|
265
|
+
* @param params - Parameters for generating the connection
|
|
266
|
+
* @returns WebSocket URL and OAuth authentication headers
|
|
267
|
+
*
|
|
268
|
+
* @throws Error if bearer token is empty
|
|
269
|
+
* @throws Error if runtime ARN format is invalid
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* const client = new RuntimeClient({ region: 'us-west-2' })
|
|
274
|
+
*
|
|
275
|
+
* // With OAuth bearer token
|
|
276
|
+
* const { url, headers } = await client.generateWsConnectionOAuth({
|
|
277
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime',
|
|
278
|
+
* bearerToken: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...',
|
|
279
|
+
* endpointName: 'DEFAULT'
|
|
280
|
+
* })
|
|
281
|
+
*
|
|
282
|
+
* // Use with WebSocket client
|
|
283
|
+
* const ws = new WebSocket(url, { headers })
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
async generateWsConnectionOAuth(params) {
|
|
287
|
+
// Validate bearer token
|
|
288
|
+
if (!params.bearerToken) {
|
|
289
|
+
throw new Error('Bearer token cannot be empty');
|
|
290
|
+
}
|
|
291
|
+
// Validate ARN
|
|
292
|
+
this._parseRuntimeArn(params.runtimeArn);
|
|
293
|
+
// Auto-generate session ID if not provided
|
|
294
|
+
const sessionId = params.sessionId ?? randomUUID();
|
|
295
|
+
// Build WebSocket URL
|
|
296
|
+
const wsUrl = this._buildWebSocketUrl(params.runtimeArn, params.endpointName);
|
|
297
|
+
// Convert wss:// to https:// to get host
|
|
298
|
+
const httpsUrl = wsUrl.replace('wss://', 'https://');
|
|
299
|
+
const url = new URL(httpsUrl);
|
|
300
|
+
// Generate WebSocket key (required for OAuth connections)
|
|
301
|
+
const wsKey = randomBytes(16).toString('base64');
|
|
302
|
+
// Build OAuth headers
|
|
303
|
+
const headers = {
|
|
304
|
+
Authorization: `Bearer ${params.bearerToken}`,
|
|
305
|
+
'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id': sessionId,
|
|
306
|
+
Host: url.hostname,
|
|
307
|
+
Connection: 'Upgrade',
|
|
308
|
+
Upgrade: 'websocket',
|
|
309
|
+
'Sec-WebSocket-Key': wsKey,
|
|
310
|
+
'Sec-WebSocket-Version': '13',
|
|
311
|
+
'User-Agent': 'OAuth-WebSocket-Client/1.0',
|
|
312
|
+
};
|
|
313
|
+
return {
|
|
314
|
+
url: wsUrl,
|
|
315
|
+
headers,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/runtime/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAS7D,OAAO,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,aAAa;IACf,MAAM,CAAQ;IACN,mBAAmB,CAA+B;IAEnE;;;;;OAKG;IACH,YAAY,SAA8B,EAAE;QAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAA;QACtD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAA;QACjG,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,IAAI,eAAe,EAAE,CAAA;IAC5E,CAAC;IAED;;;;;;;;OAQG;IACK,gBAAgB,CAAC,UAAkB;QACzC,MAAM,QAAQ,GAAG,2D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CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RequestContext } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get the current request context.
|
|
4
|
+
*
|
|
5
|
+
* @returns The RequestContext if called within a request scope (inside runWithContext),
|
|
6
|
+
* undefined otherwise (e.g., during app initialization or outside request handlers)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { getContext } from 'bedrock-agentcore/context'
|
|
11
|
+
*
|
|
12
|
+
* const handler = async (request, context) => {
|
|
13
|
+
* const ctx = getContext()
|
|
14
|
+
* console.log('Request ID:', ctx?.requestId)
|
|
15
|
+
* console.log('Session ID:', ctx?.sessionId)
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function getContext(): RequestContext | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Run a function within a request context scope.
|
|
22
|
+
* The context will be available via getContext() throughout the entire async call chain.
|
|
23
|
+
*
|
|
24
|
+
* This function is internal to the runtime module and should not be used directly by customers.
|
|
25
|
+
* It is automatically called by BedrockAgentCoreApp to set up context for each request.
|
|
26
|
+
*
|
|
27
|
+
* @param context - The request context to make available
|
|
28
|
+
* @param fn - The function to execute within the context scope
|
|
29
|
+
* @returns The return value of the function
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare function runWithContext<T>(context: RequestContext, fn: () => T): T;
|
|
33
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/runtime/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAahD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,IAAI,cAAc,GAAG,SAAS,CAEvD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEzE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
/**
|
|
3
|
+
* AsyncLocalStorage instance for storing request-scoped context.
|
|
4
|
+
* This provides thread-safe, automatic context propagation across async operations.
|
|
5
|
+
*
|
|
6
|
+
* This is private to prevent misuse - all context operations should go through
|
|
7
|
+
* getContext() and runWithContext() to maintain proper isolation guarantees.
|
|
8
|
+
*
|
|
9
|
+
* Note: Requires Node.js - Uses AsyncLocalStorage from 'async_hooks' module.
|
|
10
|
+
*/
|
|
11
|
+
const requestContextStorage = new AsyncLocalStorage();
|
|
12
|
+
/**
|
|
13
|
+
* Get the current request context.
|
|
14
|
+
*
|
|
15
|
+
* @returns The RequestContext if called within a request scope (inside runWithContext),
|
|
16
|
+
* undefined otherwise (e.g., during app initialization or outside request handlers)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { getContext } from 'bedrock-agentcore/context'
|
|
21
|
+
*
|
|
22
|
+
* const handler = async (request, context) => {
|
|
23
|
+
* const ctx = getContext()
|
|
24
|
+
* console.log('Request ID:', ctx?.requestId)
|
|
25
|
+
* console.log('Session ID:', ctx?.sessionId)
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function getContext() {
|
|
30
|
+
return requestContextStorage.getStore();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Run a function within a request context scope.
|
|
34
|
+
* The context will be available via getContext() throughout the entire async call chain.
|
|
35
|
+
*
|
|
36
|
+
* This function is internal to the runtime module and should not be used directly by customers.
|
|
37
|
+
* It is automatically called by BedrockAgentCoreApp to set up context for each request.
|
|
38
|
+
*
|
|
39
|
+
* @param context - The request context to make available
|
|
40
|
+
* @param fn - The function to execute within the context scope
|
|
41
|
+
* @returns The return value of the function
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export function runWithContext(context, fn) {
|
|
45
|
+
return requestContextStorage.run(context, fn);
|
|
46
|
+
}
|
|
47
|
+
// Note: runWithContext is exported for use within the runtime module (app.ts)
|
|
48
|
+
// but should not be re-exported from the public API (index.ts)
|
|
49
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/runtime/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAG/C;;;;;;;;GAQG;AACH,MAAM,qBAAqB,GAAG,IAAI,iBAAiB,EAAkB,CAAA;AAErE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,qBAAqB,CAAC,QAAQ,EAAE,CAAA;AACzC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAI,OAAuB,EAAE,EAAW;IACpE,OAAO,qBAAqB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;AAC/C,CAAC;AAED,8EAA8E;AAC9E,+DAA+D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentCore Runtime module
|
|
3
|
+
*/
|
|
4
|
+
export { BedrockAgentCoreApp } from './app.js';
|
|
5
|
+
export { RuntimeClient } from './client.js';
|
|
6
|
+
export type { BedrockAgentCoreAppConfig, ContentTypeParserConfig, InvocationHandler as Handler, RequestContext, HealthStatus, HealthCheckResponse, AsyncTaskInfo, AsyncTaskStatus, RuntimeClientConfig, GenerateWsConnectionParams, GeneratePresignedUrlParams, GenerateWsConnectionOAuthParams, WebSocketConnection, ParsedRuntimeArn, } from './types.js';
|
|
7
|
+
export { DEFAULT_PRESIGNED_URL_TIMEOUT, MAX_PRESIGNED_URL_TIMEOUT, DEFAULT_REGION, RuntimeArnSchema } from './types.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,YAAY,EACV,yBAAyB,EACzB,uBAAuB,EACvB,iBAAiB,IAAI,OAAO,EAC5B,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,+BAA+B,EAC/B,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentCore Runtime module
|
|
3
|
+
*/
|
|
4
|
+
export { BedrockAgentCoreApp } from './app.js';
|
|
5
|
+
export { RuntimeClient } from './client.js';
|
|
6
|
+
export { DEFAULT_PRESIGNED_URL_TIMEOUT, MAX_PRESIGNED_URL_TIMEOUT, DEFAULT_REGION, RuntimeArnSchema } from './types.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAiB3C,OAAO,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA"}
|