bedrock-agentcore 0.1.1 → 0.2.2
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/README.md +102 -114
- 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 +19 -0
- package/dist/src/tools/browser/client.d.ts.map +1 -1
- package/dist/src/tools/browser/client.js +56 -0
- package/dist/src/tools/browser/client.js.map +1 -1
- package/dist/src/tools/browser/index.d.ts +1 -1
- package/dist/src/tools/browser/index.d.ts.map +1 -1
- package/dist/src/tools/browser/index.js.map +1 -1
- 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/tools.d.ts +1 -1
- package/dist/src/tools/browser/integrations/vercel-ai/tools.js +1 -1
- package/dist/src/tools/browser/live-view/BrowserLiveView.d.ts +10 -0
- package/dist/src/tools/browser/live-view/BrowserLiveView.d.ts.map +1 -0
- package/dist/src/tools/browser/live-view/BrowserLiveView.js +180 -0
- package/dist/src/tools/browser/live-view/BrowserLiveView.js.map +1 -0
- package/dist/src/tools/browser/live-view/index.d.ts +4 -0
- package/dist/src/tools/browser/live-view/index.d.ts.map +1 -0
- package/dist/src/tools/browser/live-view/index.js +3 -0
- package/dist/src/tools/browser/live-view/index.js.map +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/README.md +26 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcv-ui/EULA.txt +403 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcv-ui/README.md +57 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcv-ui/dcv-ui.js +7 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcv-ui/third-party-licenses.txt +145 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/EULA.txt +403 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/README.md +50 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/dcv/broadwayh264decoder-worker.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/dcv/jsmpegdecoder-worker.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/dcv/lz4decoder-worker.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/dcv/microphoneprocessor.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/dcv.js +33 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/lib/broadway/Decoder.js +850 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/lib/jsmpeg/jsmpeg.min.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/lib/lz4/lz4_decoder.js +12 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-esm/third-party-licenses.txt +1068 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/EULA.txt +403 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/README.md +50 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/dcv/broadwayh264decoder-worker.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/dcv/jsmpegdecoder-worker.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/dcv/lz4decoder-worker.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/dcv/microphoneprocessor.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/dcv.js +33 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/lib/broadway/Decoder.js +850 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/lib/jsmpeg/jsmpeg.min.js +1 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/lib/lz4/lz4_decoder.js +12 -0
- package/dist/src/tools/browser/live-view/nice-dcv-web-client-sdk/dcvjs-umd/third-party-licenses.txt +1068 -0
- package/dist/src/tools/browser/live-view/scaling.d.ts +9 -0
- package/dist/src/tools/browser/live-view/scaling.d.ts.map +1 -0
- package/dist/src/tools/browser/live-view/scaling.js +13 -0
- package/dist/src/tools/browser/live-view/scaling.js.map +1 -0
- package/dist/src/tools/browser/types.d.ts +152 -0
- package/dist/src/tools/browser/types.d.ts.map +1 -1
- package/dist/src/tools/code-interpreter/client.d.ts +2 -0
- package/dist/src/tools/code-interpreter/client.d.ts.map +1 -1
- package/dist/src/tools/code-interpreter/client.js +31 -25
- package/dist/src/tools/code-interpreter/client.js.map +1 -1
- 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 +2 -2
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-code-tool.js +2 -2
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-command-tool.d.ts +2 -2
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/execute-command-tool.js +2 -2
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/file-operations-tool.d.ts +3 -3
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/file-operations-tool.js +2 -2
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/index.d.ts +1 -1
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/index.js +1 -1
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/tools.d.ts +1 -1
- package/dist/src/tools/code-interpreter/integrations/vercel-ai/tools.js +1 -1
- package/package.json +69 -14
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { randomUUID } from 'crypto';
|
|
4
|
+
import Fastify from 'fastify';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { runWithContext } from './context.js';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const fastifySse = require('@fastify/sse');
|
|
9
|
+
const fastifyWebsocket = require('@fastify/websocket');
|
|
10
|
+
/**
|
|
11
|
+
* Fastify-based HTTP server for hosting agents on AWS Bedrock AgentCore Runtime.
|
|
12
|
+
*
|
|
13
|
+
* This class provides an HTTP server that implements the AgentCore Runtime protocol
|
|
14
|
+
* with health check and invocation endpoints. The server runs on port 8080 and
|
|
15
|
+
* handles both JSON responses and Server-Sent Events (SSE) streaming.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const app = new BedrockAgentCoreApp({
|
|
20
|
+
* invocationHandler: {
|
|
21
|
+
* requestSchema: z.object({ message: z.string() }),
|
|
22
|
+
* process: async (request, context) => {
|
|
23
|
+
* console.log(`Processing request with session ${context.sessionId}`)
|
|
24
|
+
* return `Hello ${request.message}!`
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* app.run()
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class BedrockAgentCoreApp {
|
|
33
|
+
_app;
|
|
34
|
+
_config;
|
|
35
|
+
_handler;
|
|
36
|
+
_websocketHandler;
|
|
37
|
+
_activeTasksMap = new Map();
|
|
38
|
+
_taskCounter = 0;
|
|
39
|
+
_pingHandler;
|
|
40
|
+
_forcedPingStatus;
|
|
41
|
+
_lastStatusUpdateTime = Date.now();
|
|
42
|
+
_lastKnownStatus;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new BedrockAgentCoreApp instance.
|
|
45
|
+
*
|
|
46
|
+
* @param params - Configuration including handler and optional settings
|
|
47
|
+
*/
|
|
48
|
+
constructor(params) {
|
|
49
|
+
if (!params ||
|
|
50
|
+
typeof params !== 'object' ||
|
|
51
|
+
!params.invocationHandler ||
|
|
52
|
+
typeof params.invocationHandler.process !== 'function') {
|
|
53
|
+
throw new Error('BedrockAgentCoreApp constructor requires an object with a handler property. ' +
|
|
54
|
+
'Usage: new BedrockAgentCoreApp({ invocationHandler: { process: handler } })');
|
|
55
|
+
}
|
|
56
|
+
this._handler = params.invocationHandler;
|
|
57
|
+
this._websocketHandler = params.websocketHandler ?? undefined;
|
|
58
|
+
this._config = params.config ?? {};
|
|
59
|
+
this._pingHandler = params.pingHandler ?? undefined;
|
|
60
|
+
// Configure Fastify logger based on BedrockAgentCoreAppConfig
|
|
61
|
+
const loggerConfig = this._getLoggerConfig();
|
|
62
|
+
this._app = Fastify({
|
|
63
|
+
logger: loggerConfig,
|
|
64
|
+
disableRequestLogging: this._config.logging?.disableRequestLogging ?? ((req) => req.url === '/ping'),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Starts the Fastify server on port 8080.
|
|
69
|
+
*/
|
|
70
|
+
run() {
|
|
71
|
+
const PORT = 8080;
|
|
72
|
+
// Wait for Fastify to be ready (all plugins registered), setup routes, and start the server
|
|
73
|
+
Promise.resolve(this._registerPlugins())
|
|
74
|
+
.then(() => {
|
|
75
|
+
this._setupContentTypeParsers();
|
|
76
|
+
this._setupRoutes();
|
|
77
|
+
return this._app.listen({ port: PORT, host: '0.0.0.0' });
|
|
78
|
+
})
|
|
79
|
+
.then(() => {
|
|
80
|
+
this._app.log.info(`Server listening on port ${PORT}`);
|
|
81
|
+
})
|
|
82
|
+
.catch((error) => {
|
|
83
|
+
this._app.log.error(error);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Register an async task for health tracking.
|
|
89
|
+
*
|
|
90
|
+
* @param name - Human-readable task name
|
|
91
|
+
* @param metadata - Optional task metadata
|
|
92
|
+
* @returns Task ID for completion tracking
|
|
93
|
+
*/
|
|
94
|
+
addAsyncTask(name, metadata) {
|
|
95
|
+
const taskId = ++this._taskCounter;
|
|
96
|
+
const taskInfo = {
|
|
97
|
+
name,
|
|
98
|
+
startTime: Date.now(),
|
|
99
|
+
};
|
|
100
|
+
if (metadata) {
|
|
101
|
+
taskInfo.metadata = metadata;
|
|
102
|
+
}
|
|
103
|
+
this._activeTasksMap.set(taskId, taskInfo);
|
|
104
|
+
return taskId;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Mark an async task as complete.
|
|
108
|
+
*
|
|
109
|
+
* @param taskId - Task ID from addAsyncTask
|
|
110
|
+
* @returns True if task was found and removed
|
|
111
|
+
*/
|
|
112
|
+
completeAsyncTask(taskId) {
|
|
113
|
+
return this._activeTasksMap.delete(taskId);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get current ping status based on priority system.
|
|
117
|
+
* Priority: Forced \> Custom Handler \> Automatic
|
|
118
|
+
*
|
|
119
|
+
* @returns Current health status
|
|
120
|
+
*/
|
|
121
|
+
getCurrentPingStatus() {
|
|
122
|
+
// Priority 1: Forced status
|
|
123
|
+
if (this._forcedPingStatus) {
|
|
124
|
+
return this._forcedPingStatus;
|
|
125
|
+
}
|
|
126
|
+
// Priority 2: Custom handler
|
|
127
|
+
if (this._pingHandler) {
|
|
128
|
+
try {
|
|
129
|
+
const result = this._pingHandler();
|
|
130
|
+
// Handle both sync and async handlers
|
|
131
|
+
return result instanceof Promise ? 'Healthy' : result;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
this._app.log.warn('Custom ping handler failed, falling back to automatic');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Priority 3: Automatic based on active tasks
|
|
138
|
+
const status = this._activeTasksMap.size > 0 ? 'HealthyBusy' : 'Healthy';
|
|
139
|
+
// Track status changes
|
|
140
|
+
if (!this._lastKnownStatus || this._lastKnownStatus !== status) {
|
|
141
|
+
this._lastKnownStatus = status;
|
|
142
|
+
this._lastStatusUpdateTime = Date.now();
|
|
143
|
+
}
|
|
144
|
+
return status;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Decorator to automatically track async tasks.
|
|
148
|
+
* Status becomes HealthyBusy during execution.
|
|
149
|
+
*
|
|
150
|
+
* @param fn - Async function to wrap
|
|
151
|
+
* @returns Wrapped function with automatic task tracking
|
|
152
|
+
* @throws Error if fn is not an async function
|
|
153
|
+
*/
|
|
154
|
+
asyncTask(fn) {
|
|
155
|
+
// Validate that fn is actually an async function
|
|
156
|
+
if (fn.constructor.name !== 'AsyncFunction') {
|
|
157
|
+
throw new Error('asyncTask can only be applied to async functions');
|
|
158
|
+
}
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
160
|
+
const self = this;
|
|
161
|
+
const wrapped = async function (...args) {
|
|
162
|
+
const taskId = self.addAsyncTask(fn.name || 'anonymous');
|
|
163
|
+
try {
|
|
164
|
+
return await fn.apply(this, args);
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
self.completeAsyncTask(taskId);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
Object.defineProperty(wrapped, 'name', { value: fn.name });
|
|
171
|
+
return wrapped;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get information about currently running async tasks.
|
|
175
|
+
*
|
|
176
|
+
* @returns Task status with count and details
|
|
177
|
+
*/
|
|
178
|
+
getAsyncTaskInfo() {
|
|
179
|
+
const now = Date.now();
|
|
180
|
+
const runningJobs = Array.from(this._activeTasksMap.values()).map((task) => ({
|
|
181
|
+
name: task.name,
|
|
182
|
+
duration: (now - task.startTime) / 1000, // Convert to seconds
|
|
183
|
+
}));
|
|
184
|
+
return {
|
|
185
|
+
activeCount: this._activeTasksMap.size,
|
|
186
|
+
runningJobs,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Sets up HTTP routes for the server.
|
|
191
|
+
*/
|
|
192
|
+
_setupRoutes() {
|
|
193
|
+
// Health check endpoint
|
|
194
|
+
this._app.get('/ping', this._handlePing.bind(this));
|
|
195
|
+
// Invocation endpoint
|
|
196
|
+
this._app.post('/invocations', { sse: true }, this._handleInvocation.bind(this));
|
|
197
|
+
// WebSocket endpoint (only if handler exists)
|
|
198
|
+
if (this._websocketHandler) {
|
|
199
|
+
this._app.get('/ws', { websocket: true }, this._handleWebSocket.bind(this));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Register custom content type parsers using Fastify's native addContentTypeParser.
|
|
204
|
+
*/
|
|
205
|
+
_setupContentTypeParsers() {
|
|
206
|
+
this._config.contentTypeParsers?.forEach((parserConfig) => {
|
|
207
|
+
const { contentType, parser, parseAs, bodyLimit } = parserConfig;
|
|
208
|
+
if (parseAs === 'stream') {
|
|
209
|
+
// Use FastifyContentTypeParser for stream mode (raw request payload)
|
|
210
|
+
const opts = bodyLimit ? { bodyLimit } : {};
|
|
211
|
+
this._app.addContentTypeParser(contentType, opts, parser);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
// Use FastifyBodyParser for string/buffer modes (default to 'string' when parseAs is undefined)
|
|
215
|
+
const opts = {
|
|
216
|
+
parseAs: parseAs || 'string',
|
|
217
|
+
...(bodyLimit && { bodyLimit }),
|
|
218
|
+
};
|
|
219
|
+
this._app.addContentTypeParser(contentType, opts, parser);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Registers Fastify plugins.
|
|
225
|
+
*/
|
|
226
|
+
async _registerPlugins() {
|
|
227
|
+
await this._app.register(fastifySse);
|
|
228
|
+
if (this._websocketHandler) {
|
|
229
|
+
await this._app.register(fastifyWebsocket);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Gets the logger configuration based on BedrockAgentCoreAppConfig.
|
|
234
|
+
*
|
|
235
|
+
* @returns Fastify logger configuration
|
|
236
|
+
*/
|
|
237
|
+
_getLoggerConfig() {
|
|
238
|
+
const loggingConfig = this._config.logging;
|
|
239
|
+
// If no logging config provided, use default (enabled with info level)
|
|
240
|
+
if (!loggingConfig) {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
// If logging is explicitly disabled, return false
|
|
244
|
+
if (loggingConfig.enabled === false) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
// If no options provided, use default level
|
|
248
|
+
if (!loggingConfig.options) {
|
|
249
|
+
return { level: 'info' };
|
|
250
|
+
}
|
|
251
|
+
// Return FastifyLoggerOptions directly
|
|
252
|
+
return loggingConfig.options;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Handles health check requests.
|
|
256
|
+
*
|
|
257
|
+
* @param request - Fastify request object
|
|
258
|
+
* @param reply - Fastify reply object
|
|
259
|
+
*/
|
|
260
|
+
async _handlePing(request, reply) {
|
|
261
|
+
const status = this.getCurrentPingStatus();
|
|
262
|
+
const response = {
|
|
263
|
+
status,
|
|
264
|
+
time_of_last_update: new Date(this._lastStatusUpdateTime).toISOString(),
|
|
265
|
+
};
|
|
266
|
+
await reply.send(response);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Handles agent invocation requests.
|
|
270
|
+
*
|
|
271
|
+
* @param request - Fastify request object
|
|
272
|
+
* @param reply - Fastify reply object
|
|
273
|
+
*/
|
|
274
|
+
async _handleInvocation(request, reply) {
|
|
275
|
+
try {
|
|
276
|
+
// Extract context
|
|
277
|
+
const context = this._extractContext(request);
|
|
278
|
+
// Validate sessionId
|
|
279
|
+
if (!context.sessionId) {
|
|
280
|
+
await reply.status(400).send({
|
|
281
|
+
error: 'Missing sessionId. Provide via x-amzn-bedrock-agentcore-runtime-session-id header or request body.',
|
|
282
|
+
});
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
// Validate request body with schema if provided
|
|
286
|
+
let handlerRequest;
|
|
287
|
+
if (this._handler.requestSchema) {
|
|
288
|
+
try {
|
|
289
|
+
handlerRequest = await this._handler.requestSchema.parseAsync(request.body);
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
if (error instanceof z.ZodError) {
|
|
293
|
+
await reply.status(400).send({
|
|
294
|
+
error: 'Invalid request body format',
|
|
295
|
+
details: error.issues,
|
|
296
|
+
});
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
handlerRequest = request.body;
|
|
304
|
+
}
|
|
305
|
+
// Invoke handler with context
|
|
306
|
+
const result = await runWithContext(context, async () => {
|
|
307
|
+
return await this._handler.process(handlerRequest, context);
|
|
308
|
+
});
|
|
309
|
+
// Check if result is an async generator (streaming response)
|
|
310
|
+
if (this._isAsyncGenerator(result)) {
|
|
311
|
+
if (reply.sse) {
|
|
312
|
+
// Wrap streaming in context so getContext() works during iteration
|
|
313
|
+
await runWithContext(context, async () => {
|
|
314
|
+
await this._handleStreamingResponse(reply, result);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
await reply.status(406).send({
|
|
319
|
+
error: 'Streaming response requires Accept: text/event-stream header. Please include this header in your request to receive streaming data.',
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
// Return non-streaming response
|
|
325
|
+
if (reply.sse) {
|
|
326
|
+
// SSE mode active but not streaming - respond based on client's Accept header
|
|
327
|
+
const acceptHeader = request.headers.accept || 'application/json';
|
|
328
|
+
if (acceptHeader.includes('application/json') || acceptHeader.includes('*/*')) {
|
|
329
|
+
await reply.type('application/json').send(result);
|
|
330
|
+
}
|
|
331
|
+
else if (acceptHeader.includes('text/plain')) {
|
|
332
|
+
const text = typeof result === 'string' ? result : JSON.stringify(result);
|
|
333
|
+
await reply.type('text/plain').send(text);
|
|
334
|
+
}
|
|
335
|
+
else if (acceptHeader.includes('application/octet-stream')) {
|
|
336
|
+
const buffer = Buffer.isBuffer(result) ? result : Buffer.from(JSON.stringify(result));
|
|
337
|
+
await reply.type('application/octet-stream').send(buffer);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
// Default to JSON
|
|
341
|
+
await reply.type('application/json').send(result);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
await reply.send(result);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
// Handle errors
|
|
351
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
352
|
+
await reply.status(500).send({
|
|
353
|
+
error: errorMessage,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Checks if a value is an async generator.
|
|
359
|
+
*
|
|
360
|
+
* @param value - Value to check
|
|
361
|
+
* @returns True if the value is an async generator
|
|
362
|
+
*/
|
|
363
|
+
_isAsyncGenerator(value) {
|
|
364
|
+
return (value !== null &&
|
|
365
|
+
value !== undefined &&
|
|
366
|
+
typeof value === 'object' &&
|
|
367
|
+
'next' in value &&
|
|
368
|
+
typeof value.next === 'function' &&
|
|
369
|
+
'return' in value &&
|
|
370
|
+
typeof value.return === 'function' &&
|
|
371
|
+
'throw' in value &&
|
|
372
|
+
typeof value.throw === 'function' &&
|
|
373
|
+
Symbol.asyncIterator in value &&
|
|
374
|
+
typeof value[Symbol.asyncIterator] === 'function');
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Handles streaming response using Server-Sent Events (SSE) via Fastify SSE plugin.
|
|
378
|
+
*
|
|
379
|
+
* @param reply - Fastify reply object
|
|
380
|
+
* @param generator - Async generator that yields data chunks
|
|
381
|
+
*/
|
|
382
|
+
async _handleStreamingResponse(reply, generator) {
|
|
383
|
+
try {
|
|
384
|
+
await reply.sse.keepAlive();
|
|
385
|
+
// Stream data chunks
|
|
386
|
+
for await (const chunk of generator) {
|
|
387
|
+
// Stop if client disconnected
|
|
388
|
+
if (!reply.sse.isConnected) {
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
// Send SSE message
|
|
392
|
+
await reply.sse.send(chunk);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
// Send error event if still connected
|
|
397
|
+
if (reply.sse && reply.sse.isConnected) {
|
|
398
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
399
|
+
await reply.sse.send({
|
|
400
|
+
event: 'error',
|
|
401
|
+
data: { error: errorMessage },
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
this._app.log.error(error, 'Error during streaming SSE events');
|
|
406
|
+
throw new Error('Error during streaming SSE events');
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
finally {
|
|
410
|
+
// Close the SSE connection
|
|
411
|
+
if (reply.sse) {
|
|
412
|
+
reply.sse.close();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Handles WebSocket connections at /ws endpoint.
|
|
418
|
+
*
|
|
419
|
+
* @param connection - Fastify WebSocket connection
|
|
420
|
+
* @param request - Fastify request object
|
|
421
|
+
*/
|
|
422
|
+
async _handleWebSocket(connection, request) {
|
|
423
|
+
try {
|
|
424
|
+
// Extract context from WebSocket request
|
|
425
|
+
const context = this._extractContext(request);
|
|
426
|
+
request.log.info({ sessionId: context.sessionId }, 'WebSocket connection established');
|
|
427
|
+
// Call the user's WebSocket handler with context (guaranteed to exist since route is conditionally registered)
|
|
428
|
+
await runWithContext(context, async () => {
|
|
429
|
+
return await this._websocketHandler(connection, context);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
request.log.error({ error: error instanceof Error ? error.message : String(error) }, 'WebSocket handler error');
|
|
434
|
+
try {
|
|
435
|
+
connection.close(1011, 'Internal server error');
|
|
436
|
+
}
|
|
437
|
+
catch (closeError) {
|
|
438
|
+
request.log.error({ closeError: closeError instanceof Error ? closeError.message : String(closeError) }, 'Error closing WebSocket');
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Extracts request context from the incoming request.
|
|
444
|
+
*
|
|
445
|
+
* @param request - Fastify request object
|
|
446
|
+
* @returns Request context with sessionId, headers, and request-scoped logger
|
|
447
|
+
*/
|
|
448
|
+
_extractContext(request) {
|
|
449
|
+
// Extract sessionId from AWS header or body
|
|
450
|
+
const sessionId = request.headers['x-amzn-bedrock-agentcore-runtime-session-id'] ||
|
|
451
|
+
request.body?.sessionId ||
|
|
452
|
+
'';
|
|
453
|
+
// Extract request ID or generate if missing
|
|
454
|
+
const requestId = request.headers['x-amzn-bedrock-agentcore-runtime-request-id'] || randomUUID();
|
|
455
|
+
// Extract OAuth2 callback URL
|
|
456
|
+
const oauth2CallbackUrl = request.headers['oauth2callbackurl'];
|
|
457
|
+
// Filter headers to include only Authorization and Custom-* headers
|
|
458
|
+
const filteredHeaders = {};
|
|
459
|
+
for (const [key, value] of Object.entries(request.headers)) {
|
|
460
|
+
const lowerKey = key.toLowerCase();
|
|
461
|
+
const stringValue = typeof value === 'string' ? value : Array.isArray(value) ? value.join(', ') : undefined;
|
|
462
|
+
if (stringValue) {
|
|
463
|
+
// Include Authorization header
|
|
464
|
+
if (lowerKey === 'authorization') {
|
|
465
|
+
filteredHeaders[key] = stringValue;
|
|
466
|
+
}
|
|
467
|
+
// Include Custom-* headers
|
|
468
|
+
else if (lowerKey.startsWith('x-amzn-bedrock-agentcore-runtime-custom-')) {
|
|
469
|
+
filteredHeaders[key] = stringValue;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
// Extract workload token from header (if present)
|
|
474
|
+
const workloadAccessToken = request.headers['workloadaccesstoken'];
|
|
475
|
+
return {
|
|
476
|
+
sessionId,
|
|
477
|
+
headers: filteredHeaders,
|
|
478
|
+
workloadAccessToken,
|
|
479
|
+
requestId,
|
|
480
|
+
oauth2CallbackUrl,
|
|
481
|
+
log: request.log,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/runtime/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAuBvB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAC1C,MAAM,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,mBAAmB;IACb,IAAI,CAAiB;IACrB,OAAO,CAA2B;IAClC,QAAQ,CAA2E;IAC5F,iBAAiB,CAA8B;IACtC,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;IAChE,YAAY,GAAW,CAAC,CAAA;IACxB,YAAY,CAA0D;IACtE,iBAAiB,CAAe;IAChC,qBAAqB,GAAW,IAAI,CAAC,GAAG,EAAE,CAAA;IAC1C,gBAAgB,CAAe;IAEvC;;;;OAIG;IACH,YAAY,MAA0C;QACpD,IACE,CAAC,MAAM;YACP,OAAO,MAAM,KAAK,QAAQ;YAC1B,CAAC,MAAM,CAAC,iBAAiB;YACzB,OAAO,MAAM,CAAC,iBAAiB,CAAC,OAAO,KAAK,UAAU,EACtD,CAAC;YACD,MAAM,IAAI,KAAK,CACb,8EAA8E;gBAC5E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A;QAE5G,8BAA8B;QAC9B,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAuB,CAAA;QAEpF,oEAAoE;QACpE,MAAM,eAAe,GAA2B,EAAE,CAAA;QAClD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3D,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;YAClC,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YAE3G,IAAI,WAAW,EAAE,CAAC;gBAChB,+BAA+B;gBAC/B,IAAI,QAAQ,KAAK,eAAe,EAAE,CAAC;oBACjC,eAAe,CAAC,GAAG,CAAC,GAAG,WAAW,CAAA;gBACpC,CAAC;gBACD,2BAA2B;qBACtB,IAAI,QAAQ,CAAC,UAAU,CAAC,0CAA0C,CAAC,EAAE,CAAC;oBACzE,eAAe,CAAC,GAAG,CAAC,GAAG,WAAW,CAAA;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;QAED,kDAAkD;QAClD,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAuB,CAAA;QAExF,OAAO;YACL,SAAS;YACT,OAAO,EAAE,eAAe;YACxB,mBAAmB;YACnB,SAAS;YACT,iBAAiB;YACjB,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { RuntimeClientConfig, GenerateWsConnectionParams, GeneratePresignedUrlParams, GenerateWsConnectionOAuthParams, WebSocketConnection } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Client for generating WebSocket authentication for AgentCore Runtime.
|
|
4
|
+
*
|
|
5
|
+
* This client provides authentication credentials for WebSocket connections
|
|
6
|
+
* to AgentCore Runtime endpoints, allowing applications to establish
|
|
7
|
+
* bidirectional streaming connections with agent runtimes.
|
|
8
|
+
*
|
|
9
|
+
* The client is stateless and does not manage session lifecycle. Each method
|
|
10
|
+
* call is independent and takes the runtime ARN as a parameter.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const client = new RuntimeClient({ region: 'us-west-2' })
|
|
15
|
+
*
|
|
16
|
+
* // Generate WebSocket connection with SigV4 headers
|
|
17
|
+
* const { url, headers } = await client.generateWsConnection({
|
|
18
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-runtime',
|
|
19
|
+
* endpointName: 'DEFAULT'
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* // Generate presigned WebSocket URL
|
|
23
|
+
* const presignedUrl = await client.generatePresignedUrl({
|
|
24
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-runtime',
|
|
25
|
+
* expires: 300
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class RuntimeClient {
|
|
30
|
+
readonly region: string;
|
|
31
|
+
private readonly credentialsProvider;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new RuntimeClient instance.
|
|
34
|
+
*
|
|
35
|
+
* @param config - Configuration options for the client
|
|
36
|
+
* @throws Error if region is not provided via config or AWS_REGION environment variable
|
|
37
|
+
*/
|
|
38
|
+
constructor(config?: RuntimeClientConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Parses runtime ARN and extracts components.
|
|
41
|
+
*
|
|
42
|
+
* @param runtimeArn - Full runtime ARN
|
|
43
|
+
* @returns Parsed ARN components
|
|
44
|
+
* @throws Error if ARN format is invalid
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
private _parseRuntimeArn;
|
|
49
|
+
/**
|
|
50
|
+
* Builds WebSocket URL with query parameters.
|
|
51
|
+
*
|
|
52
|
+
* @param runtimeArn - Full runtime ARN
|
|
53
|
+
* @param endpointName - Optional endpoint name for qualifier param
|
|
54
|
+
* @param customHeaders - Optional custom query parameters
|
|
55
|
+
* @returns WebSocket URL with query parameters
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
private _buildWebSocketUrl;
|
|
60
|
+
/**
|
|
61
|
+
* Generates WebSocket URL and SigV4 signed headers for runtime connection.
|
|
62
|
+
*
|
|
63
|
+
* This method creates authentication credentials for establishing a WebSocket
|
|
64
|
+
* connection to an AgentCore Runtime. The returned headers include AWS SigV4
|
|
65
|
+
* signature for authentication.
|
|
66
|
+
*
|
|
67
|
+
* @param params - Parameters for generating the connection
|
|
68
|
+
* @returns WebSocket URL and authentication headers
|
|
69
|
+
*
|
|
70
|
+
* @throws Error if runtime ARN format is invalid
|
|
71
|
+
* @throws Error if AWS credentials are not available
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const client = new RuntimeClient({ region: 'us-west-2' })
|
|
76
|
+
*
|
|
77
|
+
* // With auto-generated session ID
|
|
78
|
+
* const { url, headers } = await client.generateWsConnection({
|
|
79
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime'
|
|
80
|
+
* })
|
|
81
|
+
*
|
|
82
|
+
* // With custom session ID and endpoint
|
|
83
|
+
* const connection = await client.generateWsConnection({
|
|
84
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime',
|
|
85
|
+
* sessionId: 'my-session-123',
|
|
86
|
+
* endpointName: 'DEFAULT'
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
generateWsConnection(params: GenerateWsConnectionParams): Promise<WebSocketConnection>;
|
|
91
|
+
/**
|
|
92
|
+
* Generates a presigned WebSocket URL for runtime connection.
|
|
93
|
+
*
|
|
94
|
+
* Presigned URLs include authentication in query parameters, allowing
|
|
95
|
+
* frontend clients to connect without managing AWS credentials.
|
|
96
|
+
*
|
|
97
|
+
* @param params - Parameters for generating the presigned URL
|
|
98
|
+
* @returns Presigned WebSocket URL with authentication in query parameters
|
|
99
|
+
*
|
|
100
|
+
* @throws Error if expires exceeds maximum (300 seconds)
|
|
101
|
+
* @throws Error if runtime ARN format is invalid
|
|
102
|
+
* @throws Error if AWS credentials are not available
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const client = new RuntimeClient({ region: 'us-west-2' })
|
|
107
|
+
*
|
|
108
|
+
* // Basic presigned URL
|
|
109
|
+
* const url = await client.generatePresignedUrl({
|
|
110
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime'
|
|
111
|
+
* })
|
|
112
|
+
*
|
|
113
|
+
* // With custom parameters
|
|
114
|
+
* const url = await client.generatePresignedUrl({
|
|
115
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime',
|
|
116
|
+
* sessionId: 'my-session-123',
|
|
117
|
+
* endpointName: 'DEFAULT',
|
|
118
|
+
* customHeaders: { 'custom-param': 'value' },
|
|
119
|
+
* expires: 300
|
|
120
|
+
* })
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
generatePresignedUrl(params: GeneratePresignedUrlParams): Promise<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Generates WebSocket URL and OAuth headers for runtime connection.
|
|
126
|
+
*
|
|
127
|
+
* This method uses OAuth bearer token authentication instead of AWS SigV4.
|
|
128
|
+
* Suitable for scenarios where OAuth tokens are used for authentication.
|
|
129
|
+
* Does NOT require AWS credentials.
|
|
130
|
+
*
|
|
131
|
+
* @param params - Parameters for generating the connection
|
|
132
|
+
* @returns WebSocket URL and OAuth authentication headers
|
|
133
|
+
*
|
|
134
|
+
* @throws Error if bearer token is empty
|
|
135
|
+
* @throws Error if runtime ARN format is invalid
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const client = new RuntimeClient({ region: 'us-west-2' })
|
|
140
|
+
*
|
|
141
|
+
* // With OAuth bearer token
|
|
142
|
+
* const { url, headers } = await client.generateWsConnectionOAuth({
|
|
143
|
+
* runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime',
|
|
144
|
+
* bearerToken: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...',
|
|
145
|
+
* endpointName: 'DEFAULT'
|
|
146
|
+
* })
|
|
147
|
+
*
|
|
148
|
+
* // Use with WebSocket client
|
|
149
|
+
* const ws = new WebSocket(url, { headers })
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
generateWsConnectionOAuth(params: GenerateWsConnectionOAuthParams): Promise<WebSocketConnection>;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/runtime/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,+BAA+B,EAC/B,mBAAmB,EAEpB,MAAM,YAAY,CAAA;AAGnB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,aAAa;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA+B;IAEnE;;;;;OAKG;gBACS,MAAM,GAAE,mBAAwB;IAS5C;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAiBxB;;;;;;;;;OASG;IACH,OAAO,CAAC,kBAAkB;IAyB1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA8C5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC;IAuE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,yBAAyB,CAAC,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAuCvG"}
|