@superblocksteam/sdk-api 2.0.103 → 2.0.104-next.1
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 +58 -299
- package/dist/api/definition.js +1 -1
- package/dist/api/definition.js.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +0 -2
- package/dist/api/index.js.map +1 -1
- package/dist/errors.d.ts +0 -44
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -32
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -9
- package/dist/index.js.map +1 -1
- package/dist/integrations/anthropic/types.d.ts +3 -22
- package/dist/integrations/anthropic/types.d.ts.map +1 -1
- package/dist/integrations/athena/types.d.ts +2 -2
- package/dist/integrations/base/index.d.ts +1 -1
- package/dist/integrations/base/index.d.ts.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.d.ts +4 -48
- package/dist/integrations/base/rest-api-integration-client.d.ts.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.js +2 -110
- package/dist/integrations/base/rest-api-integration-client.js.map +1 -1
- package/dist/integrations/base/types.d.ts +1 -67
- package/dist/integrations/base/types.d.ts.map +1 -1
- package/dist/integrations/bigquery/types.d.ts +3 -3
- package/dist/integrations/databricks/types.d.ts +3 -3
- package/dist/integrations/documentation.test.d.ts +2 -0
- package/dist/integrations/documentation.test.d.ts.map +1 -0
- package/dist/integrations/documentation.test.js +83 -0
- package/dist/integrations/documentation.test.js.map +1 -0
- package/dist/integrations/index.d.ts +1 -1
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/lakebase/types.d.ts +4 -4
- package/dist/integrations/mariadb/types.d.ts +2 -2
- package/dist/integrations/mssql/types.d.ts +2 -2
- package/dist/integrations/mysql/types.d.ts +4 -4
- package/dist/integrations/openai_v2/types.d.ts +4 -22
- package/dist/integrations/openai_v2/types.d.ts.map +1 -1
- package/dist/integrations/oracledb/types.d.ts +2 -2
- package/dist/integrations/registry.d.ts +0 -16
- package/dist/integrations/registry.d.ts.map +1 -1
- package/dist/integrations/registry.js +38 -38
- package/dist/integrations/registry.js.map +1 -1
- package/dist/integrations/registry.test.js +1 -3
- package/dist/integrations/registry.test.js.map +1 -1
- package/dist/integrations/restapiintegration/types.d.ts +2 -2
- package/dist/integrations/restapiintegration/types.d.ts.map +1 -1
- package/dist/integrations/snowflakecortex/client.d.ts +1 -2
- package/dist/integrations/snowflakecortex/client.d.ts.map +1 -1
- package/dist/integrations/snowflakecortex/client.js +1 -2
- package/dist/integrations/snowflakecortex/client.js.map +1 -1
- package/dist/integrations/snowflakecortex/types.d.ts +3 -4
- package/dist/integrations/snowflakecortex/types.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +0 -3
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -6
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/definition.ts +1 -1
- package/src/api/index.ts +0 -4
- package/src/errors.ts +0 -48
- package/src/index.ts +2 -28
- package/src/integrations/anthropic/README.md +5 -101
- package/src/integrations/anthropic/types.ts +3 -29
- package/src/integrations/athena/README.md +4 -4
- package/src/integrations/athena/types.ts +2 -2
- package/src/integrations/base/index.ts +0 -2
- package/src/integrations/base/rest-api-integration-client.ts +4 -153
- package/src/integrations/base/types.ts +3 -74
- package/src/integrations/bigquery/README.md +28 -3
- package/src/integrations/bigquery/types.ts +3 -3
- package/src/integrations/cohere/README.md +11 -11
- package/src/integrations/databricks/README.md +29 -4
- package/src/integrations/databricks/types.ts +3 -3
- package/src/integrations/documentation.test.ts +122 -0
- package/src/integrations/fireworks/README.md +43 -17
- package/src/integrations/googleanalytics/README.md +2 -2
- package/src/integrations/googledrive/README.md +2 -2
- package/src/integrations/groq/README.md +41 -34
- package/src/integrations/gsheets/README.md +2 -2
- package/src/integrations/index.ts +0 -1
- package/src/integrations/lakebase/types.ts +4 -4
- package/src/integrations/launchdarkly/README.md +2 -2
- package/src/integrations/mariadb/README.md +3 -3
- package/src/integrations/mariadb/types.ts +2 -2
- package/src/integrations/mistral/README.md +39 -13
- package/src/integrations/mssql/README.md +3 -3
- package/src/integrations/mssql/types.ts +2 -2
- package/src/integrations/mysql/README.md +4 -4
- package/src/integrations/mysql/types.ts +4 -4
- package/src/integrations/openai_v2/README.md +44 -116
- package/src/integrations/openai_v2/types.ts +4 -29
- package/src/integrations/oracledb/README.md +3 -3
- package/src/integrations/oracledb/types.ts +2 -2
- package/src/integrations/pagerduty/README.md +2 -2
- package/src/integrations/perplexity/README.md +2 -1
- package/src/integrations/registry.test.ts +1 -3
- package/src/integrations/registry.ts +38 -127
- package/src/integrations/restapiintegration/README.md +4 -43
- package/src/integrations/restapiintegration/types.ts +2 -8
- package/src/integrations/sendgrid/README.md +2 -2
- package/src/integrations/snowflakecortex/README.md +4 -53
- package/src/integrations/snowflakecortex/client.ts +2 -3
- package/src/integrations/snowflakecortex/types.ts +3 -11
- package/src/integrations/stabilityai/README.md +2 -2
- package/src/runtime/index.ts +1 -23
- package/dist/api/streaming.d.ts +0 -229
- package/dist/api/streaming.d.ts.map +0 -1
- package/dist/api/streaming.js +0 -107
- package/dist/api/streaming.js.map +0 -1
- package/dist/api/streaming.test.d.ts +0 -5
- package/dist/api/streaming.test.d.ts.map +0 -1
- package/dist/api/streaming.test.js +0 -364
- package/dist/api/streaming.test.js.map +0 -1
- package/dist/runtime/execute.d.ts +0 -128
- package/dist/runtime/execute.d.ts.map +0 -1
- package/dist/runtime/execute.js +0 -84
- package/dist/runtime/execute.js.map +0 -1
- package/dist/runtime/streaming-context.d.ts +0 -49
- package/dist/runtime/streaming-context.d.ts.map +0 -1
- package/dist/runtime/streaming-context.js +0 -71
- package/dist/runtime/streaming-context.js.map +0 -1
- package/dist/runtime/streaming-executor.d.ts +0 -159
- package/dist/runtime/streaming-executor.d.ts.map +0 -1
- package/dist/runtime/streaming-executor.js +0 -229
- package/dist/runtime/streaming-executor.js.map +0 -1
- package/src/api/streaming.test.ts +0 -433
- package/src/api/streaming.ts +0 -303
- package/src/runtime/execute.ts +0 -221
- package/src/runtime/streaming-context.ts +0 -164
- package/src/runtime/streaming-executor.ts +0 -367
package/dist/runtime/index.js
CHANGED
|
@@ -4,15 +4,10 @@
|
|
|
4
4
|
* Provides the execution engine for running compiled APIs,
|
|
5
5
|
* including context creation, validation, and error handling.
|
|
6
6
|
*/
|
|
7
|
-
//
|
|
8
|
-
export { execute, isStreamingApi, } from "./execute.js";
|
|
9
|
-
// Main executor (for non-streaming APIs)
|
|
7
|
+
// Main executor
|
|
10
8
|
export { executeApi, } from "./executor.js";
|
|
11
|
-
// Streaming executor (for streaming APIs)
|
|
12
|
-
export { executeStreamingApi, createStreamingApiGenerator, } from "./streaming-executor.js";
|
|
13
9
|
// Context factories
|
|
14
10
|
export { createApiContext } from "./context.js";
|
|
15
|
-
export { createStreamingApiContext, } from "./streaming-context.js";
|
|
16
11
|
// Error types
|
|
17
12
|
export { SdkError, InputValidationError, OutputValidationError, IntegrationNotFoundError, IntegrationError, ExecutionError, ErrorCode, } from "./errors.js";
|
|
18
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gBAAgB;AAChB,OAAO,EACL,UAAU,GAKX,MAAM,eAAe,CAAC;AAEvB,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAA6B,MAAM,cAAc,CAAC;AAE3E,cAAc;AACd,OAAO,EACL,QAAQ,EACR,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,cAAc,EACd,SAAS,GAEV,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
package/src/api/definition.ts
CHANGED
|
@@ -52,7 +52,7 @@ import type { ApiConfig, ApiContext, AnyIntegrationRef } from "../types.js";
|
|
|
52
52
|
|
|
53
53
|
// ---------------------------------------------------------------------------
|
|
54
54
|
// Entry point setter — used by the Vite plugin to stamp the source file path
|
|
55
|
-
// onto the next api()
|
|
55
|
+
// onto the next api() call. ESM top-level execution is
|
|
56
56
|
// synchronous, so the prepended __setEntryPoint() always runs before api().
|
|
57
57
|
// ---------------------------------------------------------------------------
|
|
58
58
|
|
package/src/api/index.ts
CHANGED
|
@@ -4,7 +4,3 @@
|
|
|
4
4
|
|
|
5
5
|
export { api, __setEntryPoint } from "./definition.js";
|
|
6
6
|
export type { CompiledApi } from "./definition.js";
|
|
7
|
-
|
|
8
|
-
// Streaming API support
|
|
9
|
-
export { streamingApi, isStreamingApi } from "./streaming.js";
|
|
10
|
-
export type { StreamingApiConfig, CompiledStreamingApi } from "./streaming.js";
|
package/src/errors.ts
CHANGED
|
@@ -80,51 +80,3 @@ export class CodeExecutionError extends Error {
|
|
|
80
80
|
Object.setPrototypeOf(this, CodeExecutionError.prototype);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Error thrown when a streamed chunk fails validation.
|
|
86
|
-
*
|
|
87
|
-
* Contains information about the chunk index, the raw chunk data,
|
|
88
|
-
* and the Zod validation error details.
|
|
89
|
-
*/
|
|
90
|
-
export class StreamChunkValidationError extends Error {
|
|
91
|
-
constructor(
|
|
92
|
-
message: string,
|
|
93
|
-
public readonly details: {
|
|
94
|
-
/** Index of the chunk that failed validation (0-based) */
|
|
95
|
-
chunkIndex: number;
|
|
96
|
-
/** The raw chunk data that failed validation */
|
|
97
|
-
chunk: unknown;
|
|
98
|
-
/** The complete Zod error object with all validation information */
|
|
99
|
-
zodError: z.ZodError;
|
|
100
|
-
},
|
|
101
|
-
) {
|
|
102
|
-
super(message);
|
|
103
|
-
this.name = "StreamChunkValidationError";
|
|
104
|
-
// Ensure proper prototype chain for instanceof checks
|
|
105
|
-
Object.setPrototypeOf(this, StreamChunkValidationError.prototype);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Error thrown when a streaming API encounters an error mid-stream.
|
|
111
|
-
*
|
|
112
|
-
* This error indicates that the stream was interrupted before completion.
|
|
113
|
-
* Contains context about where in the stream the error occurred.
|
|
114
|
-
*/
|
|
115
|
-
export class StreamError extends Error {
|
|
116
|
-
constructor(
|
|
117
|
-
message: string,
|
|
118
|
-
public readonly details?: {
|
|
119
|
-
/** Number of chunks successfully received before the error */
|
|
120
|
-
chunksReceived?: number;
|
|
121
|
-
/** The original error that caused the stream to fail */
|
|
122
|
-
originalError?: unknown;
|
|
123
|
-
},
|
|
124
|
-
) {
|
|
125
|
-
super(message);
|
|
126
|
-
this.name = "StreamError";
|
|
127
|
-
// Ensure proper prototype chain for instanceof checks
|
|
128
|
-
Object.setPrototypeOf(this, StreamError.prototype);
|
|
129
|
-
}
|
|
130
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -59,16 +59,7 @@ export { fileRefSchema, readableFileSchema } from "./files.js";
|
|
|
59
59
|
export type { FileRef, ReadableFile } from "./files.js";
|
|
60
60
|
|
|
61
61
|
// API definition and registry
|
|
62
|
-
export {
|
|
63
|
-
api,
|
|
64
|
-
__setEntryPoint,
|
|
65
|
-
type CompiledApi,
|
|
66
|
-
// Streaming API support
|
|
67
|
-
streamingApi,
|
|
68
|
-
isStreamingApi,
|
|
69
|
-
type StreamingApiConfig,
|
|
70
|
-
type CompiledStreamingApi,
|
|
71
|
-
} from "./api/index.js";
|
|
62
|
+
export { api, __setEntryPoint, type CompiledApi } from "./api/index.js";
|
|
72
63
|
|
|
73
64
|
// Type extraction utilities
|
|
74
65
|
export type { ExtractApiInput, ExtractApiOutput } from "./api/definition.js";
|
|
@@ -298,15 +289,10 @@ export type { SmtpClient, SmtpSendOptions } from "./integrations/smtp/index.js";
|
|
|
298
289
|
|
|
299
290
|
// Runtime (for orchestrator use)
|
|
300
291
|
export {
|
|
301
|
-
//
|
|
302
|
-
execute,
|
|
303
|
-
// Legacy executors (still available for specific use cases)
|
|
292
|
+
// Executor
|
|
304
293
|
executeApi,
|
|
305
|
-
executeStreamingApi,
|
|
306
|
-
createStreamingApiGenerator,
|
|
307
294
|
// Context factories
|
|
308
295
|
createApiContext,
|
|
309
|
-
createStreamingApiContext,
|
|
310
296
|
// Error types
|
|
311
297
|
SdkError,
|
|
312
298
|
InputValidationError,
|
|
@@ -318,21 +304,12 @@ export {
|
|
|
318
304
|
} from "./runtime/index.js";
|
|
319
305
|
|
|
320
306
|
export type {
|
|
321
|
-
// Unified types (recommended)
|
|
322
|
-
UnifiedExecuteApiRequest,
|
|
323
|
-
AnyCompiledApi,
|
|
324
|
-
// Legacy types (still available)
|
|
325
307
|
ExecuteApiRequest,
|
|
326
308
|
ExecuteApiResponse,
|
|
327
309
|
ExecuteApiSuccessResponse,
|
|
328
310
|
ExecuteApiErrorResponse,
|
|
329
|
-
ExecuteStreamingApiRequest,
|
|
330
|
-
StreamingApiCallbacks,
|
|
331
|
-
StreamingApiError,
|
|
332
|
-
ExecuteStreamingApiResult,
|
|
333
311
|
// Context types
|
|
334
312
|
CreateContextOptions,
|
|
335
|
-
CreateStreamingContextOptions,
|
|
336
313
|
ErrorCodeType,
|
|
337
314
|
} from "./runtime/index.js";
|
|
338
315
|
|
|
@@ -348,7 +325,6 @@ export type {
|
|
|
348
325
|
IntegrationClientImpl,
|
|
349
326
|
SupportedPluginId,
|
|
350
327
|
QueryExecutor,
|
|
351
|
-
StreamingQueryExecutor,
|
|
352
328
|
TraceMetadata,
|
|
353
329
|
CreateClientOptions,
|
|
354
330
|
} from "./integrations/index.js";
|
|
@@ -358,6 +334,4 @@ export {
|
|
|
358
334
|
RestApiValidationError,
|
|
359
335
|
QueryValidationError,
|
|
360
336
|
CodeExecutionError,
|
|
361
|
-
StreamChunkValidationError,
|
|
362
|
-
StreamError,
|
|
363
337
|
} from "./errors.js";
|
|
@@ -4,10 +4,9 @@ Interact with Anthropic's Claude API for powerful AI conversations and text gene
|
|
|
4
4
|
|
|
5
5
|
## Methods
|
|
6
6
|
|
|
7
|
-
| Method
|
|
8
|
-
|
|
|
9
|
-
| `apiRequest(options, schema, metadata?)`
|
|
10
|
-
| `streamApiRequest(options, schema, metadata?)` | Stream responses with real-time chunk validation |
|
|
7
|
+
| Method | Description |
|
|
8
|
+
| ---------------------------------------- | ----------------------------------------------------- |
|
|
9
|
+
| `apiRequest(options, schema, metadata?)` | Make any Anthropic API request with schema validation |
|
|
11
10
|
|
|
12
11
|
## Usage
|
|
13
12
|
|
|
@@ -242,89 +241,6 @@ const result = await ctx.integrations.ai.apiRequest(
|
|
|
242
241
|
);
|
|
243
242
|
```
|
|
244
243
|
|
|
245
|
-
### Streaming Messages
|
|
246
|
-
|
|
247
|
-
For real-time token streaming, use `streamApiRequest()` with `stream: true`:
|
|
248
|
-
|
|
249
|
-
```typescript
|
|
250
|
-
import { streamingApi, z, anthropic } from "@superblocksteam/sdk-api";
|
|
251
|
-
|
|
252
|
-
// Integration ID from the integrations panel
|
|
253
|
-
const PROD_ANTHROPIC = "a1b2c3d4-5678-90ab-cdef-444444444444";
|
|
254
|
-
|
|
255
|
-
// Schema for Anthropic's streaming SSE events
|
|
256
|
-
const AnthropicStreamEventSchema = z.discriminatedUnion("type", [
|
|
257
|
-
z.object({
|
|
258
|
-
type: z.literal("content_block_delta"),
|
|
259
|
-
index: z.number(),
|
|
260
|
-
delta: z.object({
|
|
261
|
-
type: z.literal("text_delta"),
|
|
262
|
-
text: z.string(),
|
|
263
|
-
}),
|
|
264
|
-
}),
|
|
265
|
-
z.object({ type: z.literal("message_start"), message: z.any() }),
|
|
266
|
-
z.object({
|
|
267
|
-
type: z.literal("content_block_start"),
|
|
268
|
-
index: z.number(),
|
|
269
|
-
content_block: z.any(),
|
|
270
|
-
}),
|
|
271
|
-
z.object({ type: z.literal("content_block_stop"), index: z.number() }),
|
|
272
|
-
z.object({
|
|
273
|
-
type: z.literal("message_delta"),
|
|
274
|
-
delta: z.any(),
|
|
275
|
-
usage: z.any(),
|
|
276
|
-
}),
|
|
277
|
-
z.object({ type: z.literal("message_stop") }),
|
|
278
|
-
z.object({ type: z.literal("ping") }),
|
|
279
|
-
]);
|
|
280
|
-
|
|
281
|
-
export default streamingApi({
|
|
282
|
-
integrations: {
|
|
283
|
-
ai: anthropic(PROD_ANTHROPIC),
|
|
284
|
-
},
|
|
285
|
-
|
|
286
|
-
input: z.object({ prompt: z.string() }),
|
|
287
|
-
chunk: z.object({ type: z.literal("text"), text: z.string() }),
|
|
288
|
-
|
|
289
|
-
async *run(ctx, { prompt }) {
|
|
290
|
-
const stream = ctx.integrations.ai.streamApiRequest(
|
|
291
|
-
{
|
|
292
|
-
method: "POST",
|
|
293
|
-
path: "/v1/messages",
|
|
294
|
-
body: {
|
|
295
|
-
model: "claude-3-5-sonnet-20241022",
|
|
296
|
-
max_tokens: 1024,
|
|
297
|
-
stream: true, // Enable streaming
|
|
298
|
-
messages: [{ role: "user", content: prompt }],
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
{ chunk: AnthropicStreamEventSchema },
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
// Yield text chunks as they arrive
|
|
305
|
-
for await (const event of stream) {
|
|
306
|
-
if (event.type === "content_block_delta") {
|
|
307
|
-
yield { type: "text" as const, text: event.delta.text };
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
},
|
|
311
|
-
});
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
#### Streaming Event Types
|
|
315
|
-
|
|
316
|
-
Claude's streaming API sends these event types:
|
|
317
|
-
|
|
318
|
-
| Event Type | Description |
|
|
319
|
-
| --------------------- | ------------------------------------------- |
|
|
320
|
-
| `message_start` | Initial message metadata (model, id, usage) |
|
|
321
|
-
| `content_block_start` | Start of a content block (text, tool_use) |
|
|
322
|
-
| `content_block_delta` | Incremental text or tool input |
|
|
323
|
-
| `content_block_stop` | End of a content block |
|
|
324
|
-
| `message_delta` | Final message metadata (stop_reason, usage) |
|
|
325
|
-
| `message_stop` | Stream complete |
|
|
326
|
-
| `ping` | Keep-alive ping |
|
|
327
|
-
|
|
328
244
|
## Trace Metadata
|
|
329
245
|
|
|
330
246
|
All methods accept an optional `metadata` parameter as the last argument for diagnostics labeling. See the [root SDK README](../../../README.md#trace-metadata) for details.
|
|
@@ -333,7 +249,7 @@ All methods accept an optional `metadata` parameter as the last argument for dia
|
|
|
333
249
|
|
|
334
250
|
### No Specialized Methods
|
|
335
251
|
|
|
336
|
-
The Anthropic client only provides `apiRequest()
|
|
252
|
+
The Anthropic client only provides `apiRequest()`. There are no other specialized methods:
|
|
337
253
|
|
|
338
254
|
```typescript
|
|
339
255
|
// WRONG - These methods do not exist
|
|
@@ -474,7 +390,7 @@ const result = await ctx.integrations.ai.apiRequest(
|
|
|
474
390
|
## Error Handling
|
|
475
391
|
|
|
476
392
|
```typescript
|
|
477
|
-
import { RestApiValidationError
|
|
393
|
+
import { RestApiValidationError } from "@superblocksteam/sdk-api";
|
|
478
394
|
|
|
479
395
|
try {
|
|
480
396
|
const result = await ctx.integrations.ai.apiRequest(
|
|
@@ -487,18 +403,6 @@ try {
|
|
|
487
403
|
console.error("Actual response:", error.details.data);
|
|
488
404
|
}
|
|
489
405
|
}
|
|
490
|
-
|
|
491
|
-
// For streaming requests
|
|
492
|
-
try {
|
|
493
|
-
for await (const chunk of stream) {
|
|
494
|
-
// Process chunk
|
|
495
|
-
}
|
|
496
|
-
} catch (error) {
|
|
497
|
-
if (error instanceof StreamChunkValidationError) {
|
|
498
|
-
console.error("Chunk validation failed at index:", error.details.chunkIndex);
|
|
499
|
-
console.error("Raw chunk:", error.details.chunk);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
406
|
```
|
|
503
407
|
|
|
504
408
|
## API Reference
|
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { BaseIntegrationClient } from "../../types.js";
|
|
6
|
-
import type {
|
|
7
|
-
SupportsApiRequest,
|
|
8
|
-
SupportsStreamingApiRequest,
|
|
9
|
-
} from "../base/index.js";
|
|
6
|
+
import type { SupportsApiRequest } from "../base/index.js";
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* Anthropic client for Claude AI model interactions.
|
|
13
10
|
*
|
|
14
|
-
* Provides the generic apiRequest() method for any Anthropic API endpoint
|
|
15
|
-
* and streamApiRequest() for streaming responses.
|
|
11
|
+
* Provides the generic apiRequest() method for any Anthropic API endpoint.
|
|
16
12
|
* Use this to interact with Anthropic's messages API and other endpoints.
|
|
17
13
|
*
|
|
18
14
|
* @example
|
|
@@ -58,31 +54,9 @@ import type {
|
|
|
58
54
|
* }
|
|
59
55
|
* );
|
|
60
56
|
*
|
|
61
|
-
* // Or use streaming for real-time responses
|
|
62
|
-
* const stream = anthropic.streamApiRequest(
|
|
63
|
-
* {
|
|
64
|
-
* method: 'POST',
|
|
65
|
-
* path: '/v1/messages',
|
|
66
|
-
* body: {
|
|
67
|
-
* model: 'claude-3-5-sonnet-20241022',
|
|
68
|
-
* max_tokens: 1024,
|
|
69
|
-
* stream: true,
|
|
70
|
-
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
71
|
-
* },
|
|
72
|
-
* },
|
|
73
|
-
* { chunk: StreamEventSchema }
|
|
74
|
-
* );
|
|
75
|
-
*
|
|
76
|
-
* for await (const event of stream) {
|
|
77
|
-
* // Handle streaming events
|
|
78
|
-
* }
|
|
79
57
|
* ```
|
|
80
58
|
*/
|
|
81
59
|
export interface AnthropicClient
|
|
82
|
-
extends
|
|
83
|
-
BaseIntegrationClient,
|
|
84
|
-
SupportsApiRequest,
|
|
85
|
-
SupportsStreamingApiRequest {
|
|
60
|
+
extends BaseIntegrationClient, SupportsApiRequest {
|
|
86
61
|
// apiRequest() method inherited from SupportsApiRequest
|
|
87
|
-
// streamApiRequest() method inherited from SupportsStreamingApiRequest
|
|
88
62
|
}
|
|
@@ -41,7 +41,7 @@ export default api({
|
|
|
41
41
|
const logs = await ctx.integrations.athena.query(
|
|
42
42
|
`SELECT timestamp, level, message, request_id
|
|
43
43
|
FROM logs
|
|
44
|
-
WHERE level =
|
|
44
|
+
WHERE level = ?
|
|
45
45
|
LIMIT 100`,
|
|
46
46
|
LogSchema,
|
|
47
47
|
[level],
|
|
@@ -65,8 +65,8 @@ const EventSchema = z.object({
|
|
|
65
65
|
const events = await ctx.integrations.athena.query(
|
|
66
66
|
`SELECT event_id, event_type, user_id, created_at
|
|
67
67
|
FROM events
|
|
68
|
-
WHERE date_partition =
|
|
69
|
-
AND event_type =
|
|
68
|
+
WHERE date_partition = ?
|
|
69
|
+
AND event_type = ?`,
|
|
70
70
|
EventSchema,
|
|
71
71
|
["2024-01-15", "purchase"],
|
|
72
72
|
);
|
|
@@ -138,7 +138,7 @@ Always use partition filters when possible to reduce data scanned:
|
|
|
138
138
|
```typescript
|
|
139
139
|
// GOOD - Uses partition filter
|
|
140
140
|
const logs = await ctx.integrations.athena.query(
|
|
141
|
-
"SELECT * FROM logs WHERE date_partition =
|
|
141
|
+
"SELECT * FROM logs WHERE date_partition = ?",
|
|
142
142
|
LogSchema,
|
|
143
143
|
["2024-01-15"],
|
|
144
144
|
);
|
|
@@ -25,7 +25,7 @@ import type { TraceMetadata } from "../registry.js";
|
|
|
25
25
|
* });
|
|
26
26
|
*
|
|
27
27
|
* const logs = await athena.query(
|
|
28
|
-
* 'SELECT * FROM logs WHERE level =
|
|
28
|
+
* 'SELECT * FROM logs WHERE level = ?',
|
|
29
29
|
* LogSchema,
|
|
30
30
|
* ['ERROR']
|
|
31
31
|
* );
|
|
@@ -35,7 +35,7 @@ export interface AthenaClient extends BaseIntegrationClient {
|
|
|
35
35
|
/**
|
|
36
36
|
* Execute a SQL query and validate results against a Zod schema.
|
|
37
37
|
*
|
|
38
|
-
* @param sql - SQL query string (use
|
|
38
|
+
* @param sql - SQL query string (use ? placeholders for parameters)
|
|
39
39
|
* @param schema - Zod schema to validate the query results
|
|
40
40
|
* @param params - Optional query parameters
|
|
41
41
|
* @returns Promise resolving to validated query results
|
|
@@ -10,22 +10,13 @@ import type { z } from "zod";
|
|
|
10
10
|
import type { Property } from "@superblocksteam/types/dist/src/common/v1/plugin_pb";
|
|
11
11
|
import type { Plugin as RestApiIntegrationPlugin } from "@superblocksteam/types/dist/src/plugins/restapiintegration/v1/plugin_pb";
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
StreamChunkValidationError,
|
|
16
|
-
} from "../../errors.js";
|
|
17
|
-
import type {
|
|
18
|
-
QueryExecutor,
|
|
19
|
-
StreamingQueryExecutor,
|
|
20
|
-
TraceMetadata,
|
|
21
|
-
} from "../registry.js";
|
|
13
|
+
import { RestApiValidationError } from "../../errors.js";
|
|
14
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
22
15
|
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
23
16
|
import type {
|
|
24
17
|
ApiRequestOptions,
|
|
25
18
|
ApiRequestSchema,
|
|
26
19
|
SupportsApiRequest,
|
|
27
|
-
StreamApiRequestSchema,
|
|
28
|
-
SupportsStreamingApiRequest,
|
|
29
20
|
} from "./types.js";
|
|
30
21
|
|
|
31
22
|
export type RestApiRequest = PartialMessage<RestApiIntegrationPlugin>;
|
|
@@ -35,31 +26,21 @@ export type RestApiRequest = PartialMessage<RestApiIntegrationPlugin>;
|
|
|
35
26
|
*
|
|
36
27
|
* All OpenAPI-based integration clients extend this class to inherit
|
|
37
28
|
* the generic apiRequest() method with runtime schema validation.
|
|
38
|
-
* Also supports streaming API requests when a streaming executor is provided.
|
|
39
29
|
*/
|
|
40
30
|
export abstract class RestApiIntegrationClient
|
|
41
|
-
implements
|
|
42
|
-
IntegrationClientImpl,
|
|
43
|
-
SupportsApiRequest,
|
|
44
|
-
SupportsStreamingApiRequest
|
|
31
|
+
implements IntegrationClientImpl, SupportsApiRequest
|
|
45
32
|
{
|
|
46
33
|
readonly name: string;
|
|
47
34
|
readonly pluginId: string;
|
|
48
35
|
readonly config: IntegrationConfig;
|
|
49
36
|
|
|
50
37
|
protected readonly executeQuery: QueryExecutor;
|
|
51
|
-
protected readonly executeStreamingQuery?: StreamingQueryExecutor;
|
|
52
38
|
|
|
53
|
-
constructor(
|
|
54
|
-
config: IntegrationConfig,
|
|
55
|
-
executeQuery: QueryExecutor,
|
|
56
|
-
executeStreamingQuery?: StreamingQueryExecutor,
|
|
57
|
-
) {
|
|
39
|
+
constructor(config: IntegrationConfig, executeQuery: QueryExecutor) {
|
|
58
40
|
this.name = config.name;
|
|
59
41
|
this.pluginId = config.pluginId;
|
|
60
42
|
this.config = config;
|
|
61
43
|
this.executeQuery = executeQuery;
|
|
62
|
-
this.executeStreamingQuery = executeStreamingQuery;
|
|
63
44
|
}
|
|
64
45
|
|
|
65
46
|
/**
|
|
@@ -148,134 +129,4 @@ export abstract class RestApiIntegrationClient
|
|
|
148
129
|
|
|
149
130
|
return responseParseResult.data;
|
|
150
131
|
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Execute a streaming API request with type-safe chunk validation.
|
|
154
|
-
*
|
|
155
|
-
* Returns an AsyncIterable that yields validated chunks as they arrive.
|
|
156
|
-
* Each chunk is validated against the provided schema before being yielded.
|
|
157
|
-
*
|
|
158
|
-
* @param options - Request configuration including method, path, params, and body
|
|
159
|
-
* @param schema - Zod schemas for request body and chunk validation
|
|
160
|
-
* @param metadata - Optional trace metadata for observability (label, description)
|
|
161
|
-
* @returns AsyncIterable yielding validated chunks
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```typescript
|
|
165
|
-
* const ChunkSchema = z.object({
|
|
166
|
-
* id: z.string(),
|
|
167
|
-
* choices: z.array(z.object({
|
|
168
|
-
* delta: z.object({
|
|
169
|
-
* content: z.string().optional(),
|
|
170
|
-
* }),
|
|
171
|
-
* })),
|
|
172
|
-
* });
|
|
173
|
-
*
|
|
174
|
-
* const stream = client.streamApiRequest(
|
|
175
|
-
* {
|
|
176
|
-
* method: 'POST',
|
|
177
|
-
* path: '/v1/chat/completions',
|
|
178
|
-
* body: {
|
|
179
|
-
* model: 'gpt-4',
|
|
180
|
-
* stream: true,
|
|
181
|
-
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
182
|
-
* },
|
|
183
|
-
* },
|
|
184
|
-
* { chunk: ChunkSchema },
|
|
185
|
-
* { label: 'openai.chatCompletions', description: 'Stream chat completion' }
|
|
186
|
-
* );
|
|
187
|
-
*
|
|
188
|
-
* for await (const chunk of stream) {
|
|
189
|
-
* console.log(chunk.choices[0]?.delta?.content);
|
|
190
|
-
* }
|
|
191
|
-
* ```
|
|
192
|
-
*/
|
|
193
|
-
async *streamApiRequest<TBody, TChunk>(
|
|
194
|
-
options: ApiRequestOptions<TBody>,
|
|
195
|
-
schema: StreamApiRequestSchema<TBody, TChunk>,
|
|
196
|
-
metadata?: TraceMetadata,
|
|
197
|
-
): AsyncIterable<TChunk> {
|
|
198
|
-
// Validate that streaming is supported
|
|
199
|
-
if (!this.executeStreamingQuery) {
|
|
200
|
-
throw new Error(
|
|
201
|
-
`Streaming is not supported for integration "${this.name}". ` +
|
|
202
|
-
"The orchestrator must provide a streaming query executor.",
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Validate request body against schema if both are present.
|
|
207
|
-
// Body schema is optional — if not provided, the body is sent unvalidated.
|
|
208
|
-
if (options.body !== undefined && schema?.body) {
|
|
209
|
-
const bodyParseResult = schema.body.safeParse(options.body);
|
|
210
|
-
if (!bodyParseResult.success) {
|
|
211
|
-
throw new RestApiValidationError(
|
|
212
|
-
`Request body validation failed: ${bodyParseResult.error.message}`,
|
|
213
|
-
{
|
|
214
|
-
zodError: bodyParseResult.error,
|
|
215
|
-
data: options.body,
|
|
216
|
-
},
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Convert headers to Property array
|
|
222
|
-
const headers: PartialMessage<Property>[] = [];
|
|
223
|
-
if (options.headers) {
|
|
224
|
-
for (const [key, value] of Object.entries(options.headers)) {
|
|
225
|
-
headers.push(this.createParam(key, value));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Convert query params to Property array
|
|
230
|
-
const params: PartialMessage<Property>[] = [];
|
|
231
|
-
if (options.params) {
|
|
232
|
-
for (const [key, value] of Object.entries(options.params)) {
|
|
233
|
-
params.push(this.createParam(key, value));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Build the request using raw HTTP mode with streaming response
|
|
238
|
-
// Note: responseType must be "raw" for streaming - the orchestrator's
|
|
239
|
-
// Stream block expects SSE responses and only works with "raw" type.
|
|
240
|
-
const request: RestApiRequest = {
|
|
241
|
-
openApiAction: "genericHttpRequest",
|
|
242
|
-
httpMethod: options.method.toUpperCase(),
|
|
243
|
-
urlPath: options.path,
|
|
244
|
-
headers,
|
|
245
|
-
params,
|
|
246
|
-
responseType: "raw",
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
// Add body if provided
|
|
250
|
-
if (options.body !== undefined) {
|
|
251
|
-
request.body = JSON.stringify(options.body);
|
|
252
|
-
request.bodyType = "jsonBody";
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Execute the streaming request
|
|
256
|
-
const stream = this.executeStreamingQuery(
|
|
257
|
-
request as Record<string, unknown>,
|
|
258
|
-
metadata,
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
// Validate and yield each chunk
|
|
262
|
-
let chunkIndex = 0;
|
|
263
|
-
for await (const rawChunk of stream) {
|
|
264
|
-
const parseResult = schema.chunk.safeParse(rawChunk);
|
|
265
|
-
|
|
266
|
-
if (!parseResult.success) {
|
|
267
|
-
throw new StreamChunkValidationError(
|
|
268
|
-
`Chunk validation failed at index ${chunkIndex}: ${parseResult.error.message}`,
|
|
269
|
-
{
|
|
270
|
-
chunkIndex,
|
|
271
|
-
chunk: rawChunk,
|
|
272
|
-
zodError: parseResult.error,
|
|
273
|
-
},
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
yield parseResult.data;
|
|
278
|
-
chunkIndex++;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
132
|
}
|