@superblocksteam/sdk-api 0.0.15-mcp.2 → 0.0.16-agentcore.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/dist/api/definition.test.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/agentcore/client.d.ts +21 -0
- package/dist/integrations/agentcore/client.d.ts.map +1 -0
- package/dist/integrations/agentcore/client.js +109 -0
- package/dist/integrations/agentcore/client.js.map +1 -0
- package/dist/integrations/agentcore/client.test.d.ts +2 -0
- package/dist/integrations/agentcore/client.test.d.ts.map +1 -0
- package/dist/integrations/agentcore/client.test.js +115 -0
- package/dist/integrations/agentcore/client.test.js.map +1 -0
- package/dist/integrations/agentcore/index.d.ts +3 -0
- package/dist/integrations/agentcore/index.d.ts.map +1 -0
- package/dist/integrations/agentcore/index.js +2 -0
- package/dist/integrations/agentcore/index.js.map +1 -0
- package/dist/integrations/agentcore/types.d.ts +43 -0
- package/dist/integrations/agentcore/types.d.ts.map +1 -0
- package/dist/integrations/agentcore/types.js +2 -0
- package/dist/integrations/agentcore/types.js.map +1 -0
- package/dist/integrations/base/decode-worker-binary-response.d.ts.map +1 -1
- package/dist/integrations/base/decode-worker-binary-response.js +7 -2
- package/dist/integrations/base/decode-worker-binary-response.js.map +1 -1
- package/dist/integrations/base/decode-worker-binary-response.test.js +12 -1
- package/dist/integrations/base/decode-worker-binary-response.test.js.map +1 -1
- package/dist/integrations/base/graphql-integration-client.d.ts +1 -1
- package/dist/integrations/base/graphql-integration-client.d.ts.map +1 -1
- package/dist/integrations/declarations.d.ts +10 -0
- package/dist/integrations/declarations.d.ts.map +1 -1
- package/dist/integrations/declarations.js +9 -0
- package/dist/integrations/declarations.js.map +1 -1
- package/dist/integrations/index.d.ts +3 -1
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +2 -1
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/registry.d.ts +1 -0
- package/dist/integrations/registry.d.ts.map +1 -1
- package/dist/integrations/registry.js +4 -0
- package/dist/integrations/registry.js.map +1 -1
- package/package.json +10 -14
- package/src/api/definition.test.ts +0 -1
- package/src/index.ts +9 -0
- package/src/integrations/agentcore/README.md +49 -0
- package/src/integrations/agentcore/client.test.ts +166 -0
- package/src/integrations/agentcore/client.ts +168 -0
- package/src/integrations/agentcore/docs.manifest.json +5 -0
- package/src/integrations/agentcore/index.ts +8 -0
- package/src/integrations/agentcore/types.ts +56 -0
- package/src/integrations/base/decode-worker-binary-response.test.ts +15 -1
- package/src/integrations/base/decode-worker-binary-response.ts +8 -3
- package/src/integrations/base/graphql-integration-client.ts +1 -1
- package/src/integrations/declarations.ts +16 -0
- package/src/integrations/index.ts +10 -0
- package/src/integrations/registry.ts +5 -0
- package/src/integrations/restapiintegration/client.test.ts +1 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Amazon Bedrock AgentCore client.
|
|
3
|
+
*
|
|
4
|
+
* The step fields match the worker plugin. They are declared here because the
|
|
5
|
+
* published types package does not include the plugin yet.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
RestApiValidationError,
|
|
12
|
+
restApiValidationErrorFromZodError,
|
|
13
|
+
} from "../../errors.js";
|
|
14
|
+
import { IntegrationError } from "../../runtime/errors.js";
|
|
15
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
16
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
17
|
+
import type {
|
|
18
|
+
AgentCoreClient,
|
|
19
|
+
AgentCoreInvokeAgentRuntimeOptions,
|
|
20
|
+
AgentCoreInvokeHarnessOptions,
|
|
21
|
+
AgentCoreInvokeHarnessResult,
|
|
22
|
+
} from "./types.js";
|
|
23
|
+
|
|
24
|
+
const HarnessResultSchema = z.object({
|
|
25
|
+
kind: z.literal("harness"),
|
|
26
|
+
text: z.string(),
|
|
27
|
+
toolCalls: z.array(
|
|
28
|
+
z.object({
|
|
29
|
+
name: z.string(),
|
|
30
|
+
toolUseId: z.string().optional(),
|
|
31
|
+
result: z.string(),
|
|
32
|
+
failed: z.boolean(),
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
stopReason: z.string(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const RuntimeResultSchema = z.object({
|
|
39
|
+
kind: z.literal("runtime"),
|
|
40
|
+
response: z.unknown(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function payloadText(payload: unknown): string {
|
|
44
|
+
if (typeof payload === "string") {
|
|
45
|
+
return payload;
|
|
46
|
+
}
|
|
47
|
+
if (payload === undefined) {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return JSON.stringify(payload) ?? "";
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new RestApiValidationError(
|
|
54
|
+
`Payload cannot be sent as JSON: ${error instanceof Error ? error.message : String(error)}`,
|
|
55
|
+
{ data: payload, zodError: new z.ZodError([]) },
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class AgentCoreClientImpl
|
|
61
|
+
implements AgentCoreClient, IntegrationClientImpl
|
|
62
|
+
{
|
|
63
|
+
readonly config: IntegrationConfig;
|
|
64
|
+
private readonly executeQuery: QueryExecutor;
|
|
65
|
+
|
|
66
|
+
constructor(config: IntegrationConfig, executeQuery: QueryExecutor) {
|
|
67
|
+
this.config = config;
|
|
68
|
+
this.executeQuery = executeQuery;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get name(): string {
|
|
72
|
+
return this.config.name;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get pluginId(): string {
|
|
76
|
+
return this.config.pluginId;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async invokeHarness(
|
|
80
|
+
prompt: string,
|
|
81
|
+
options?: AgentCoreInvokeHarnessOptions,
|
|
82
|
+
): Promise<AgentCoreInvokeHarnessResult> {
|
|
83
|
+
if (prompt.trim() === "") {
|
|
84
|
+
throw new RestApiValidationError("Prompt is required.", {
|
|
85
|
+
data: prompt,
|
|
86
|
+
zodError: new z.ZodError([]),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const result = await this.run(
|
|
90
|
+
"invokeHarness",
|
|
91
|
+
{
|
|
92
|
+
prompt,
|
|
93
|
+
...(options?.sessionKey ? { sessionKey: options.sessionKey } : {}),
|
|
94
|
+
},
|
|
95
|
+
options?.label,
|
|
96
|
+
);
|
|
97
|
+
const parsed = HarnessResultSchema.safeParse(result);
|
|
98
|
+
if (!parsed.success) {
|
|
99
|
+
throw restApiValidationErrorFromZodError(
|
|
100
|
+
"AgentCore invokeHarness returned an unexpected result",
|
|
101
|
+
parsed.error,
|
|
102
|
+
result,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const { text, toolCalls, stopReason } = parsed.data;
|
|
106
|
+
return { text, toolCalls, stopReason };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async invokeAgentRuntime<T>(
|
|
110
|
+
payload: unknown,
|
|
111
|
+
schema: z.ZodType<T>,
|
|
112
|
+
options?: AgentCoreInvokeAgentRuntimeOptions,
|
|
113
|
+
): Promise<T> {
|
|
114
|
+
const body = payloadText(payload);
|
|
115
|
+
if (body.trim() === "") {
|
|
116
|
+
throw new RestApiValidationError("Payload is required.", {
|
|
117
|
+
data: payload,
|
|
118
|
+
zodError: new z.ZodError([]),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const result = await this.run(
|
|
122
|
+
"invokeAgentRuntime",
|
|
123
|
+
{
|
|
124
|
+
payload: body,
|
|
125
|
+
...(options?.contentType ? { contentType: options.contentType } : {}),
|
|
126
|
+
...(options?.accept ? { accept: options.accept } : {}),
|
|
127
|
+
...(options?.sessionKey ? { sessionKey: options.sessionKey } : {}),
|
|
128
|
+
},
|
|
129
|
+
options?.label,
|
|
130
|
+
);
|
|
131
|
+
const runtime = RuntimeResultSchema.safeParse(result);
|
|
132
|
+
if (!runtime.success) {
|
|
133
|
+
throw restApiValidationErrorFromZodError(
|
|
134
|
+
"AgentCore invokeAgentRuntime returned an unexpected result",
|
|
135
|
+
runtime.error,
|
|
136
|
+
result,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
const parsed = schema.safeParse(runtime.data.response);
|
|
140
|
+
if (!parsed.success) {
|
|
141
|
+
throw restApiValidationErrorFromZodError(
|
|
142
|
+
"AgentCore runtime response failed validation",
|
|
143
|
+
parsed.error,
|
|
144
|
+
runtime.data.response,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return parsed.data;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private async run(
|
|
151
|
+
operation: string,
|
|
152
|
+
request: Record<string, unknown>,
|
|
153
|
+
label: string | undefined,
|
|
154
|
+
): Promise<unknown> {
|
|
155
|
+
try {
|
|
156
|
+
return await this.executeQuery(request, undefined, trace(label));
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (error instanceof IntegrationError) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
throw new IntegrationError(this.config.name, operation, error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function trace(label: string | undefined): TraceMetadata | undefined {
|
|
167
|
+
return label ? { label } : undefined;
|
|
168
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import type { BaseIntegrationClient } from "../../types.js";
|
|
4
|
+
|
|
5
|
+
/** One tool the harness ran while answering. */
|
|
6
|
+
export interface AgentCoreToolCall {
|
|
7
|
+
name: string;
|
|
8
|
+
toolUseId?: string;
|
|
9
|
+
result: string;
|
|
10
|
+
failed: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** What a harness call returns after the stream finishes. */
|
|
14
|
+
export interface AgentCoreInvokeHarnessResult {
|
|
15
|
+
text: string;
|
|
16
|
+
toolCalls: AgentCoreToolCall[];
|
|
17
|
+
stopReason: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AgentCoreInvokeHarnessOptions {
|
|
21
|
+
/** Stable key for this conversation. Omitted keys get a new session on each call. */
|
|
22
|
+
sessionKey?: string;
|
|
23
|
+
/** Shown in the Trace View. */
|
|
24
|
+
label?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AgentCoreInvokeAgentRuntimeOptions {
|
|
28
|
+
sessionKey?: string;
|
|
29
|
+
/** Defaults to application/json on the worker when omitted. */
|
|
30
|
+
contentType?: string;
|
|
31
|
+
/** Response content type to request. Defaults to application/json on the worker. */
|
|
32
|
+
accept?: string;
|
|
33
|
+
label?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface AgentCoreClient extends BaseIntegrationClient {
|
|
37
|
+
/**
|
|
38
|
+
* Call a harness agent with a prompt.
|
|
39
|
+
* The integration's agent ARN must be a harness ARN.
|
|
40
|
+
*/
|
|
41
|
+
invokeHarness(
|
|
42
|
+
prompt: string,
|
|
43
|
+
options?: AgentCoreInvokeHarnessOptions,
|
|
44
|
+
): Promise<AgentCoreInvokeHarnessResult>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Call a runtime agent with a payload and validate the response.
|
|
48
|
+
* Objects are sent as JSON. A string is sent unchanged.
|
|
49
|
+
* The integration's agent ARN must be a runtime ARN.
|
|
50
|
+
*/
|
|
51
|
+
invokeAgentRuntime<T>(
|
|
52
|
+
payload: unknown,
|
|
53
|
+
schema: z.ZodType<T>,
|
|
54
|
+
options?: AgentCoreInvokeAgentRuntimeOptions,
|
|
55
|
+
): Promise<T>;
|
|
56
|
+
}
|
|
@@ -43,6 +43,20 @@ describe("decodeWorkerBinaryResponse", () => {
|
|
|
43
43
|
expect(result.byteLength).toBe(0);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
it("decodes a multi-megabyte base64 payload without overflowing the stack", () => {
|
|
47
|
+
const byteLength = 6 * 1024 * 1024;
|
|
48
|
+
const payload = Buffer.alloc(byteLength, 7).toString("base64");
|
|
49
|
+
|
|
50
|
+
const result = decodeWorkerBinaryResponse({
|
|
51
|
+
type: "Buffer",
|
|
52
|
+
data: payload,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(result.byteLength).toBe(byteLength);
|
|
56
|
+
expect(result[0]).toBe(7);
|
|
57
|
+
expect(result[byteLength - 1]).toBe(7);
|
|
58
|
+
});
|
|
59
|
+
|
|
46
60
|
it("decodes an empty base64 string to a zero-length Uint8Array", () => {
|
|
47
61
|
const result = decodeWorkerBinaryResponse({ type: "Buffer", data: "" });
|
|
48
62
|
|
|
@@ -62,7 +76,7 @@ describe("decodeWorkerBinaryResponse", () => {
|
|
|
62
76
|
).toThrow(RestApiValidationError);
|
|
63
77
|
});
|
|
64
78
|
|
|
65
|
-
it.each(["@@@@", "A=BC", "====", "QUI"])(
|
|
79
|
+
it.each(["@@@@", "A=BC", "====", "QUI", "A===", "AAAA=", "AA==AAAA"])(
|
|
66
80
|
"rejects non-base64 string data %j",
|
|
67
81
|
(data) => {
|
|
68
82
|
expect(() =>
|
|
@@ -9,11 +9,16 @@ export { REDACTED_BINARY_RESPONSE_DATA };
|
|
|
9
9
|
|
|
10
10
|
// Node's decoder accepts missing and misplaced padding. A worker payload is
|
|
11
11
|
// a canonical padded string, so reject anything else before decoding.
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// A grouped `{4}` repeat overflows V8's regexp backtrack stack around 4MB
|
|
13
|
+
// of base64. A flat class plus a length check accepts the same strings.
|
|
14
|
+
const BASE64_ALPHABET = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
15
|
+
|
|
16
|
+
function isCanonicalBase64(data: string): boolean {
|
|
17
|
+
return data.length % 4 === 0 && BASE64_ALPHABET.test(data);
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
function decodeBase64(data: string): Uint8Array | undefined {
|
|
16
|
-
if (!
|
|
21
|
+
if (!isCanonicalBase64(data)) {
|
|
17
22
|
return undefined;
|
|
18
23
|
}
|
|
19
24
|
return new Uint8Array(Buffer.from(data, "base64"));
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
+
import type { AgentCoreClient } from "./agentcore/index.js";
|
|
34
35
|
import type { AirtableClient } from "./airtable/index.js";
|
|
35
36
|
import type { AnthropicClient } from "./anthropic/index.js";
|
|
36
37
|
import type { AsanaClient } from "./asana/index.js";
|
|
@@ -339,6 +340,9 @@ export type SnowflakePostgresRef = IntegrationRef<
|
|
|
339
340
|
/** Reference to an SMTP integration */
|
|
340
341
|
export type SmtpRef = IntegrationRef<"smtp", SmtpClient>;
|
|
341
342
|
|
|
343
|
+
/** Reference to an Amazon Bedrock AgentCore integration */
|
|
344
|
+
export type AgentCoreRef = IntegrationRef<"agentcore", AgentCoreClient>;
|
|
345
|
+
|
|
342
346
|
/** Reference to an MCP Server integration */
|
|
343
347
|
export type McpIntegrationRef = IntegrationRef<"mcpintegration", McpClient>;
|
|
344
348
|
|
|
@@ -1043,6 +1047,18 @@ export function smtp<T extends string>(id: LiteralString<T>): SmtpRef {
|
|
|
1043
1047
|
return createRef<"smtp", SmtpClient, T>("smtp", id);
|
|
1044
1048
|
}
|
|
1045
1049
|
|
|
1050
|
+
/**
|
|
1051
|
+
* Declare an Amazon Bedrock AgentCore integration.
|
|
1052
|
+
*
|
|
1053
|
+
* @param id - The integration ID (UUID)
|
|
1054
|
+
* @returns An integration reference for use in the API config
|
|
1055
|
+
*/
|
|
1056
|
+
export function agentcore<T extends string>(
|
|
1057
|
+
id: LiteralString<T>,
|
|
1058
|
+
): AgentCoreRef {
|
|
1059
|
+
return createRef<"agentcore", AgentCoreClient, T>("agentcore", id);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1046
1062
|
/**
|
|
1047
1063
|
* Declare an MCP Server integration.
|
|
1048
1064
|
*
|
|
@@ -65,6 +65,7 @@ export {
|
|
|
65
65
|
bigquery,
|
|
66
66
|
mongodb,
|
|
67
67
|
dynamodb,
|
|
68
|
+
agentcore,
|
|
68
69
|
cosmosdb,
|
|
69
70
|
s3,
|
|
70
71
|
gcs,
|
|
@@ -145,6 +146,7 @@ export {
|
|
|
145
146
|
type LakebaseRef,
|
|
146
147
|
type SnowflakePostgresRef,
|
|
147
148
|
type SmtpRef,
|
|
149
|
+
type AgentCoreRef,
|
|
148
150
|
type McpIntegrationRef,
|
|
149
151
|
type RestApiIntegrationRef,
|
|
150
152
|
} from "./declarations.js";
|
|
@@ -368,6 +370,14 @@ export type {
|
|
|
368
370
|
DynamoDBScanOptions,
|
|
369
371
|
} from "./dynamodb/index.js";
|
|
370
372
|
export { DynamoDBClientImpl } from "./dynamodb/index.js";
|
|
373
|
+
export type {
|
|
374
|
+
AgentCoreClient,
|
|
375
|
+
AgentCoreInvokeAgentRuntimeOptions,
|
|
376
|
+
AgentCoreInvokeHarnessOptions,
|
|
377
|
+
AgentCoreInvokeHarnessResult,
|
|
378
|
+
AgentCoreToolCall,
|
|
379
|
+
} from "./agentcore/index.js";
|
|
380
|
+
export { AgentCoreClientImpl } from "./agentcore/index.js";
|
|
371
381
|
|
|
372
382
|
// CosmosDB client
|
|
373
383
|
export type { CosmosDBClient, CosmosDBQueryOptions } from "./cosmosdb/index.js";
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* and provides factory functions for creating clients.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { AgentCoreClientImpl } from "./agentcore/index.js";
|
|
8
9
|
import { AirtableClientImpl } from "./airtable/index.js";
|
|
9
10
|
import { AnthropicClientImpl } from "./anthropic/index.js";
|
|
10
11
|
import { AsanaClientImpl } from "./asana/index.js";
|
|
@@ -127,6 +128,7 @@ export const SUPPORTED_PLUGINS = {
|
|
|
127
128
|
// REST API integrations
|
|
128
129
|
mongodb: "mongodb",
|
|
129
130
|
dynamodb: "dynamodb",
|
|
131
|
+
agentcore: "agentcore",
|
|
130
132
|
cosmosdb: "cosmosdb",
|
|
131
133
|
s3: "s3",
|
|
132
134
|
gcs: "gcs",
|
|
@@ -382,6 +384,9 @@ export function createClient(
|
|
|
382
384
|
case SUPPORTED_PLUGINS.dynamodb:
|
|
383
385
|
return new DynamoDBClientImpl(config, executeQuery);
|
|
384
386
|
|
|
387
|
+
case SUPPORTED_PLUGINS.agentcore:
|
|
388
|
+
return new AgentCoreClientImpl(config, executeQuery);
|
|
389
|
+
|
|
385
390
|
case SUPPORTED_PLUGINS.cosmosdb:
|
|
386
391
|
return new CosmosDBClientImpl(config, executeQuery);
|
|
387
392
|
|
|
@@ -4,7 +4,7 @@ import { z } from "zod";
|
|
|
4
4
|
import type { ActionResponseType } from "@superblocksteam/shared";
|
|
5
5
|
|
|
6
6
|
import { RestApiValidationError } from "../../errors.js";
|
|
7
|
-
import { REST_API_RESPONSE_TYPES } from "../base/types.js";
|
|
7
|
+
import type { REST_API_RESPONSE_TYPES } from "../base/types.js";
|
|
8
8
|
import type { IntegrationConfig } from "../types.js";
|
|
9
9
|
import { RestApiIntegrationPluginClientImpl } from "./client.js";
|
|
10
10
|
|