@superblocksteam/sdk-api 2.0.103 → 2.0.104-next.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/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/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/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/openai_v2/types.d.ts +4 -22
- package/dist/integrations/openai_v2/types.d.ts.map +1 -1
- 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/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/cohere/README.md +11 -11
- 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/launchdarkly/README.md +2 -2
- package/src/integrations/mistral/README.md +39 -13
- package/src/integrations/openai_v2/README.md +44 -116
- package/src/integrations/openai_v2/types.ts +4 -29
- 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/api/streaming.d.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Streaming API definition function.
|
|
3
|
-
*
|
|
4
|
-
* This module provides the `streamingApi()` function used to define TypeScript-based APIs
|
|
5
|
-
* that yield chunks over time, enabling real-time streaming from LLMs and other sources.
|
|
6
|
-
*/
|
|
7
|
-
import type { z } from "zod";
|
|
8
|
-
import { type IntegrationDeclaration } from "../integrations/declarations.js";
|
|
9
|
-
import type { ApiContext, AnyIntegrationRef } from "../types.js";
|
|
10
|
-
/**
|
|
11
|
-
* Configuration for defining a streaming TypeScript-based API.
|
|
12
|
-
*
|
|
13
|
-
* @template TInput - Zod schema type for input validation
|
|
14
|
-
* @template TChunk - Zod schema type for each streamed chunk
|
|
15
|
-
* @template TIntegrations - Record of integration declarations
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { streamingApi, z, anthropic } from '@superblocksteam/sdk-api';
|
|
20
|
-
*
|
|
21
|
-
* export default streamingApi({
|
|
22
|
-
* integrations: {
|
|
23
|
-
* ai: anthropic('Production Anthropic'),
|
|
24
|
-
* },
|
|
25
|
-
*
|
|
26
|
-
* input: z.object({
|
|
27
|
-
* prompt: z.string(),
|
|
28
|
-
* }),
|
|
29
|
-
*
|
|
30
|
-
* chunk: z.object({
|
|
31
|
-
* type: z.literal('text-delta'),
|
|
32
|
-
* text: z.string(),
|
|
33
|
-
* }),
|
|
34
|
-
*
|
|
35
|
-
* async *run(ctx, { prompt }) {
|
|
36
|
-
* const stream = ctx.integrations.ai.streamApiRequest(
|
|
37
|
-
* {
|
|
38
|
-
* method: 'POST',
|
|
39
|
-
* path: '/v1/messages',
|
|
40
|
-
* body: {
|
|
41
|
-
* model: 'claude-3-5-sonnet-20241022',
|
|
42
|
-
* max_tokens: 1024,
|
|
43
|
-
* stream: true,
|
|
44
|
-
* messages: [{ role: 'user', content: prompt }],
|
|
45
|
-
* },
|
|
46
|
-
* },
|
|
47
|
-
* { chunk: AnthropicStreamEventSchema }
|
|
48
|
-
* );
|
|
49
|
-
*
|
|
50
|
-
* for await (const event of stream) {
|
|
51
|
-
* if (event.type === 'content_block_delta') {
|
|
52
|
-
* yield { type: 'text-delta' as const, text: event.delta.text };
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* },
|
|
56
|
-
* });
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
export interface StreamingApiConfig<TInput extends z.ZodType, TChunk extends z.ZodType, TIntegrations extends Record<string, AnyIntegrationRef> = Record<string, never>> {
|
|
60
|
-
/**
|
|
61
|
-
* Name for this API.
|
|
62
|
-
*
|
|
63
|
-
* Used for identification in execution logs and debugging.
|
|
64
|
-
*/
|
|
65
|
-
name: string;
|
|
66
|
-
/**
|
|
67
|
-
* Plain-language summary of what this API does and which integrations it uses,
|
|
68
|
-
* written for a non-technical audience.
|
|
69
|
-
*
|
|
70
|
-
* This field is auto-generated by the AI agent when creating or editing an API.
|
|
71
|
-
*/
|
|
72
|
-
description?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Integration declarations for this API.
|
|
75
|
-
*
|
|
76
|
-
* Declare integrations upfront to enable type-safe access via `ctx.integrations`
|
|
77
|
-
* and to allow the runtime to authenticate integrations before execution.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* integrations: {
|
|
82
|
-
* ai: anthropic('Production Anthropic'),
|
|
83
|
-
* db: postgres('Cache DB'),
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
integrations?: TIntegrations;
|
|
88
|
-
/** Zod schema for input validation */
|
|
89
|
-
input: TInput;
|
|
90
|
-
/**
|
|
91
|
-
* Zod schema for validating each streamed chunk.
|
|
92
|
-
*
|
|
93
|
-
* Every chunk yielded by the run function is validated against this schema.
|
|
94
|
-
* Validation errors will terminate the stream.
|
|
95
|
-
*/
|
|
96
|
-
chunk: TChunk;
|
|
97
|
-
/**
|
|
98
|
-
* The streaming API implementation function (async generator).
|
|
99
|
-
*
|
|
100
|
-
* @param ctx - Execution context with access to integrations
|
|
101
|
-
* @param input - Validated input parameters (can be destructured)
|
|
102
|
-
* @yields Chunks that are validated against the chunk schema
|
|
103
|
-
*/
|
|
104
|
-
run: (ctx: ApiContext<TIntegrations>, input: z.infer<TInput>) => AsyncIterable<z.infer<TChunk>>;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* A compiled streaming API definition ready for execution.
|
|
108
|
-
*
|
|
109
|
-
* @template TInput - The inferred input type
|
|
110
|
-
* @template TChunk - The inferred chunk type
|
|
111
|
-
*/
|
|
112
|
-
export interface CompiledStreamingApi<TInput = unknown, TChunk = unknown> {
|
|
113
|
-
/** Name of the API for identification in logs and debugging */
|
|
114
|
-
readonly name: string;
|
|
115
|
-
/** Plain-language summary of what this API does */
|
|
116
|
-
readonly description?: string;
|
|
117
|
-
/**
|
|
118
|
-
* Source file path relative to the app root (e.g. "server/apis/Chat/api.ts").
|
|
119
|
-
* Injected automatically by the Vite plugin — not authored by the user.
|
|
120
|
-
*/
|
|
121
|
-
readonly entryPoint?: string;
|
|
122
|
-
/** Zod schema for validating inputs */
|
|
123
|
-
readonly inputSchema: z.ZodType<TInput>;
|
|
124
|
-
/**
|
|
125
|
-
* Zod schema for validating each streamed chunk.
|
|
126
|
-
*
|
|
127
|
-
* Every chunk yielded by the API is validated against this schema
|
|
128
|
-
* before being sent to the client.
|
|
129
|
-
*/
|
|
130
|
-
readonly chunkSchema: z.ZodType<TChunk>;
|
|
131
|
-
/**
|
|
132
|
-
* The streaming API implementation function.
|
|
133
|
-
*
|
|
134
|
-
* @param ctx - Execution context
|
|
135
|
-
* @param input - Validated input parameters
|
|
136
|
-
* @returns AsyncIterable yielding validated chunks
|
|
137
|
-
*/
|
|
138
|
-
readonly run: (ctx: ApiContext<Record<string, AnyIntegrationRef>>, input: TInput) => AsyncIterable<TChunk>;
|
|
139
|
-
/**
|
|
140
|
-
* Declared integrations for upfront authentication.
|
|
141
|
-
*
|
|
142
|
-
* This array contains all integrations declared in the API config,
|
|
143
|
-
* allowing the runtime to authenticate them before API execution.
|
|
144
|
-
*/
|
|
145
|
-
readonly integrations: ReadonlyArray<IntegrationDeclaration>;
|
|
146
|
-
/**
|
|
147
|
-
* Runtime flag indicating this is a streaming API.
|
|
148
|
-
*
|
|
149
|
-
* Always `true` for streaming APIs. Use `isStreamingApi()` type guard
|
|
150
|
-
* to distinguish streaming APIs from regular APIs at runtime.
|
|
151
|
-
*/
|
|
152
|
-
readonly isStreaming: true;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Define a streaming TypeScript-based API with chunk validation.
|
|
156
|
-
*
|
|
157
|
-
* This function creates a compiled streaming API definition that yields
|
|
158
|
-
* chunks over time. Each chunk is validated against the provided schema.
|
|
159
|
-
*
|
|
160
|
-
* Use this for:
|
|
161
|
-
* - Real-time LLM token streaming (OpenAI, Anthropic, etc.)
|
|
162
|
-
* - Server-sent events
|
|
163
|
-
* - Long-running operations with progress updates
|
|
164
|
-
* - Any API that produces output incrementally
|
|
165
|
-
*
|
|
166
|
-
* @param config - The streaming API configuration
|
|
167
|
-
* @returns A compiled streaming API definition
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```typescript
|
|
171
|
-
* import { streamingApi, z, openai } from '@superblocksteam/sdk-api';
|
|
172
|
-
*
|
|
173
|
-
* export default streamingApi({
|
|
174
|
-
* integrations: {
|
|
175
|
-
* ai: openai('Production OpenAI'),
|
|
176
|
-
* },
|
|
177
|
-
*
|
|
178
|
-
* input: z.object({
|
|
179
|
-
* prompt: z.string(),
|
|
180
|
-
* }),
|
|
181
|
-
*
|
|
182
|
-
* chunk: z.object({
|
|
183
|
-
* content: z.string(),
|
|
184
|
-
* }),
|
|
185
|
-
*
|
|
186
|
-
* async *run(ctx, { prompt }) {
|
|
187
|
-
* const stream = ctx.integrations.ai.streamApiRequest(
|
|
188
|
-
* {
|
|
189
|
-
* method: 'POST',
|
|
190
|
-
* path: '/v1/chat/completions',
|
|
191
|
-
* body: {
|
|
192
|
-
* model: 'gpt-4',
|
|
193
|
-
* stream: true,
|
|
194
|
-
* messages: [{ role: 'user', content: prompt }],
|
|
195
|
-
* },
|
|
196
|
-
* },
|
|
197
|
-
* { chunk: OpenAIChunkSchema }
|
|
198
|
-
* );
|
|
199
|
-
*
|
|
200
|
-
* for await (const chunk of stream) {
|
|
201
|
-
* const content = chunk.choices[0]?.delta?.content;
|
|
202
|
-
* if (content) {
|
|
203
|
-
* yield { content };
|
|
204
|
-
* }
|
|
205
|
-
* }
|
|
206
|
-
* },
|
|
207
|
-
* });
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
export declare function streamingApi<TInput extends z.ZodType, TChunk extends z.ZodType, TIntegrations extends Record<string, AnyIntegrationRef> = Record<string, never>>(config: StreamingApiConfig<TInput, TChunk, TIntegrations>): CompiledStreamingApi<z.infer<TInput>, z.infer<TChunk>>;
|
|
211
|
-
/**
|
|
212
|
-
* Type guard to check if an API is a streaming API.
|
|
213
|
-
*
|
|
214
|
-
* @param api - The API to check
|
|
215
|
-
* @returns `true` if the API is a streaming API, `false` otherwise
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* import { isStreamingApi, executeApi, executeStreamingApi } from '@superblocksteam/sdk-api';
|
|
220
|
-
*
|
|
221
|
-
* if (isStreamingApi(api)) {
|
|
222
|
-
* await executeStreamingApi(api, request);
|
|
223
|
-
* } else {
|
|
224
|
-
* await executeApi(api, request);
|
|
225
|
-
* }
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
export declare function isStreamingApi(api: unknown): api is CompiledStreamingApi<unknown, unknown>;
|
|
229
|
-
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/api/streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,WAAW,kBAAkB,CACjC,MAAM,SAAS,CAAC,CAAC,OAAO,EACxB,MAAM,SAAS,CAAC,CAAC,OAAO,EACxB,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,MAAM,CAC9D,MAAM,EACN,KAAK,CACN;IAED;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC;IAE7B,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,GAAG,EAAE,CACH,GAAG,EAAE,UAAU,CAAC,aAAa,CAAC,EAC9B,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KACnB,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;CACrC;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO;IACtE,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,mDAAmD;IACnD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,uCAAuC;IACvC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAExC;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAExC;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,EAAE,CACZ,GAAG,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,EAClD,KAAK,EAAE,MAAM,KACV,aAAa,CAAC,MAAM,CAAC,CAAC;IAE3B;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IAE7D;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,YAAY,CAC1B,MAAM,SAAS,CAAC,CAAC,OAAO,EACxB,MAAM,SAAS,CAAC,CAAC,OAAO,EACxB,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,MAAM,CAC9D,MAAM,EACN,KAAK,CACN,EAED,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,GACxD,oBAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAmBxD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,CAW/C"}
|
package/dist/api/streaming.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Streaming API definition function.
|
|
3
|
-
*
|
|
4
|
-
* This module provides the `streamingApi()` function used to define TypeScript-based APIs
|
|
5
|
-
* that yield chunks over time, enabling real-time streaming from LLMs and other sources.
|
|
6
|
-
*/
|
|
7
|
-
import { extractIntegrationDeclarations, } from "../integrations/declarations.js";
|
|
8
|
-
import { consumeEntryPoint } from "./definition.js";
|
|
9
|
-
/**
|
|
10
|
-
* Define a streaming TypeScript-based API with chunk validation.
|
|
11
|
-
*
|
|
12
|
-
* This function creates a compiled streaming API definition that yields
|
|
13
|
-
* chunks over time. Each chunk is validated against the provided schema.
|
|
14
|
-
*
|
|
15
|
-
* Use this for:
|
|
16
|
-
* - Real-time LLM token streaming (OpenAI, Anthropic, etc.)
|
|
17
|
-
* - Server-sent events
|
|
18
|
-
* - Long-running operations with progress updates
|
|
19
|
-
* - Any API that produces output incrementally
|
|
20
|
-
*
|
|
21
|
-
* @param config - The streaming API configuration
|
|
22
|
-
* @returns A compiled streaming API definition
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* import { streamingApi, z, openai } from '@superblocksteam/sdk-api';
|
|
27
|
-
*
|
|
28
|
-
* export default streamingApi({
|
|
29
|
-
* integrations: {
|
|
30
|
-
* ai: openai('Production OpenAI'),
|
|
31
|
-
* },
|
|
32
|
-
*
|
|
33
|
-
* input: z.object({
|
|
34
|
-
* prompt: z.string(),
|
|
35
|
-
* }),
|
|
36
|
-
*
|
|
37
|
-
* chunk: z.object({
|
|
38
|
-
* content: z.string(),
|
|
39
|
-
* }),
|
|
40
|
-
*
|
|
41
|
-
* async *run(ctx, { prompt }) {
|
|
42
|
-
* const stream = ctx.integrations.ai.streamApiRequest(
|
|
43
|
-
* {
|
|
44
|
-
* method: 'POST',
|
|
45
|
-
* path: '/v1/chat/completions',
|
|
46
|
-
* body: {
|
|
47
|
-
* model: 'gpt-4',
|
|
48
|
-
* stream: true,
|
|
49
|
-
* messages: [{ role: 'user', content: prompt }],
|
|
50
|
-
* },
|
|
51
|
-
* },
|
|
52
|
-
* { chunk: OpenAIChunkSchema }
|
|
53
|
-
* );
|
|
54
|
-
*
|
|
55
|
-
* for await (const chunk of stream) {
|
|
56
|
-
* const content = chunk.choices[0]?.delta?.content;
|
|
57
|
-
* if (content) {
|
|
58
|
-
* yield { content };
|
|
59
|
-
* }
|
|
60
|
-
* }
|
|
61
|
-
* },
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export function streamingApi(config) {
|
|
66
|
-
// Extract integration declarations for upfront auth
|
|
67
|
-
const integrations = extractIntegrationDeclarations(config.integrations);
|
|
68
|
-
const compiled = {
|
|
69
|
-
name: config.name,
|
|
70
|
-
description: config.description,
|
|
71
|
-
entryPoint: consumeEntryPoint(),
|
|
72
|
-
inputSchema: config.input,
|
|
73
|
-
chunkSchema: config.chunk,
|
|
74
|
-
run: config.run,
|
|
75
|
-
integrations,
|
|
76
|
-
isStreaming: true,
|
|
77
|
-
};
|
|
78
|
-
return compiled;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Type guard to check if an API is a streaming API.
|
|
82
|
-
*
|
|
83
|
-
* @param api - The API to check
|
|
84
|
-
* @returns `true` if the API is a streaming API, `false` otherwise
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* import { isStreamingApi, executeApi, executeStreamingApi } from '@superblocksteam/sdk-api';
|
|
89
|
-
*
|
|
90
|
-
* if (isStreamingApi(api)) {
|
|
91
|
-
* await executeStreamingApi(api, request);
|
|
92
|
-
* } else {
|
|
93
|
-
* await executeApi(api, request);
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
export function isStreamingApi(api) {
|
|
98
|
-
return (typeof api === "object" &&
|
|
99
|
-
api !== null &&
|
|
100
|
-
"isStreaming" in api &&
|
|
101
|
-
api.isStreaming === true &&
|
|
102
|
-
"inputSchema" in api &&
|
|
103
|
-
"chunkSchema" in api &&
|
|
104
|
-
"run" in api &&
|
|
105
|
-
typeof api.run === "function");
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=streaming.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../src/api/streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EACL,8BAA8B,GAE/B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA4KpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,UAAU,YAAY,CAQ1B,MAAyD;IAEzD,oDAAoD;IACpD,MAAM,YAAY,GAAG,8BAA8B,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAEzE,MAAM,QAAQ,GAA2D;QACvE,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,iBAAiB,EAAE;QAC/B,WAAW,EAAE,MAAM,CAAC,KAAK;QACzB,WAAW,EAAE,MAAM,CAAC,KAAK;QACzB,GAAG,EAAE,MAAM,CAAC,GAGuB;QACnC,YAAY;QACZ,WAAW,EAAE,IAAI;KAClB,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAY;IAEZ,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,aAAa,IAAI,GAAG;QACnB,GAA+B,CAAC,WAAW,KAAK,IAAI;QACrD,aAAa,IAAI,GAAG;QACpB,aAAa,IAAI,GAAG;QACpB,KAAK,IAAI,GAAG;QACZ,OAAQ,GAA+B,CAAC,GAAG,KAAK,UAAU,CAC3D,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.test.d.ts","sourceRoot":"","sources":["../../src/api/streaming.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|