@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.
Files changed (134) hide show
  1. package/README.md +58 -299
  2. package/dist/api/definition.js +1 -1
  3. package/dist/api/definition.js.map +1 -1
  4. package/dist/api/index.d.ts +0 -2
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/api/index.js +0 -2
  7. package/dist/api/index.js.map +1 -1
  8. package/dist/errors.d.ts +0 -44
  9. package/dist/errors.d.ts.map +1 -1
  10. package/dist/errors.js +0 -32
  11. package/dist/errors.js.map +1 -1
  12. package/dist/index.d.ts +5 -5
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +5 -9
  15. package/dist/index.js.map +1 -1
  16. package/dist/integrations/anthropic/types.d.ts +3 -22
  17. package/dist/integrations/anthropic/types.d.ts.map +1 -1
  18. package/dist/integrations/athena/types.d.ts +2 -2
  19. package/dist/integrations/base/index.d.ts +1 -1
  20. package/dist/integrations/base/index.d.ts.map +1 -1
  21. package/dist/integrations/base/rest-api-integration-client.d.ts +4 -48
  22. package/dist/integrations/base/rest-api-integration-client.d.ts.map +1 -1
  23. package/dist/integrations/base/rest-api-integration-client.js +2 -110
  24. package/dist/integrations/base/rest-api-integration-client.js.map +1 -1
  25. package/dist/integrations/base/types.d.ts +1 -67
  26. package/dist/integrations/base/types.d.ts.map +1 -1
  27. package/dist/integrations/bigquery/types.d.ts +3 -3
  28. package/dist/integrations/databricks/types.d.ts +3 -3
  29. package/dist/integrations/documentation.test.d.ts +2 -0
  30. package/dist/integrations/documentation.test.d.ts.map +1 -0
  31. package/dist/integrations/documentation.test.js +83 -0
  32. package/dist/integrations/documentation.test.js.map +1 -0
  33. package/dist/integrations/index.d.ts +1 -1
  34. package/dist/integrations/index.d.ts.map +1 -1
  35. package/dist/integrations/index.js.map +1 -1
  36. package/dist/integrations/lakebase/types.d.ts +4 -4
  37. package/dist/integrations/mariadb/types.d.ts +2 -2
  38. package/dist/integrations/mssql/types.d.ts +2 -2
  39. package/dist/integrations/mysql/types.d.ts +4 -4
  40. package/dist/integrations/openai_v2/types.d.ts +4 -22
  41. package/dist/integrations/openai_v2/types.d.ts.map +1 -1
  42. package/dist/integrations/oracledb/types.d.ts +2 -2
  43. package/dist/integrations/registry.d.ts +0 -16
  44. package/dist/integrations/registry.d.ts.map +1 -1
  45. package/dist/integrations/registry.js +38 -38
  46. package/dist/integrations/registry.js.map +1 -1
  47. package/dist/integrations/registry.test.js +1 -3
  48. package/dist/integrations/registry.test.js.map +1 -1
  49. package/dist/integrations/restapiintegration/types.d.ts +2 -2
  50. package/dist/integrations/restapiintegration/types.d.ts.map +1 -1
  51. package/dist/integrations/snowflakecortex/client.d.ts +1 -2
  52. package/dist/integrations/snowflakecortex/client.d.ts.map +1 -1
  53. package/dist/integrations/snowflakecortex/client.js +1 -2
  54. package/dist/integrations/snowflakecortex/client.js.map +1 -1
  55. package/dist/integrations/snowflakecortex/types.d.ts +3 -4
  56. package/dist/integrations/snowflakecortex/types.d.ts.map +1 -1
  57. package/dist/runtime/index.d.ts +0 -3
  58. package/dist/runtime/index.d.ts.map +1 -1
  59. package/dist/runtime/index.js +1 -6
  60. package/dist/runtime/index.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/api/definition.ts +1 -1
  63. package/src/api/index.ts +0 -4
  64. package/src/errors.ts +0 -48
  65. package/src/index.ts +2 -28
  66. package/src/integrations/anthropic/README.md +5 -101
  67. package/src/integrations/anthropic/types.ts +3 -29
  68. package/src/integrations/athena/README.md +4 -4
  69. package/src/integrations/athena/types.ts +2 -2
  70. package/src/integrations/base/index.ts +0 -2
  71. package/src/integrations/base/rest-api-integration-client.ts +4 -153
  72. package/src/integrations/base/types.ts +3 -74
  73. package/src/integrations/bigquery/README.md +28 -3
  74. package/src/integrations/bigquery/types.ts +3 -3
  75. package/src/integrations/cohere/README.md +11 -11
  76. package/src/integrations/databricks/README.md +29 -4
  77. package/src/integrations/databricks/types.ts +3 -3
  78. package/src/integrations/documentation.test.ts +122 -0
  79. package/src/integrations/fireworks/README.md +43 -17
  80. package/src/integrations/googleanalytics/README.md +2 -2
  81. package/src/integrations/googledrive/README.md +2 -2
  82. package/src/integrations/groq/README.md +41 -34
  83. package/src/integrations/gsheets/README.md +2 -2
  84. package/src/integrations/index.ts +0 -1
  85. package/src/integrations/lakebase/types.ts +4 -4
  86. package/src/integrations/launchdarkly/README.md +2 -2
  87. package/src/integrations/mariadb/README.md +3 -3
  88. package/src/integrations/mariadb/types.ts +2 -2
  89. package/src/integrations/mistral/README.md +39 -13
  90. package/src/integrations/mssql/README.md +3 -3
  91. package/src/integrations/mssql/types.ts +2 -2
  92. package/src/integrations/mysql/README.md +4 -4
  93. package/src/integrations/mysql/types.ts +4 -4
  94. package/src/integrations/openai_v2/README.md +44 -116
  95. package/src/integrations/openai_v2/types.ts +4 -29
  96. package/src/integrations/oracledb/README.md +3 -3
  97. package/src/integrations/oracledb/types.ts +2 -2
  98. package/src/integrations/pagerduty/README.md +2 -2
  99. package/src/integrations/perplexity/README.md +2 -1
  100. package/src/integrations/registry.test.ts +1 -3
  101. package/src/integrations/registry.ts +38 -127
  102. package/src/integrations/restapiintegration/README.md +4 -43
  103. package/src/integrations/restapiintegration/types.ts +2 -8
  104. package/src/integrations/sendgrid/README.md +2 -2
  105. package/src/integrations/snowflakecortex/README.md +4 -53
  106. package/src/integrations/snowflakecortex/client.ts +2 -3
  107. package/src/integrations/snowflakecortex/types.ts +3 -11
  108. package/src/integrations/stabilityai/README.md +2 -2
  109. package/src/runtime/index.ts +1 -23
  110. package/dist/api/streaming.d.ts +0 -229
  111. package/dist/api/streaming.d.ts.map +0 -1
  112. package/dist/api/streaming.js +0 -107
  113. package/dist/api/streaming.js.map +0 -1
  114. package/dist/api/streaming.test.d.ts +0 -5
  115. package/dist/api/streaming.test.d.ts.map +0 -1
  116. package/dist/api/streaming.test.js +0 -364
  117. package/dist/api/streaming.test.js.map +0 -1
  118. package/dist/runtime/execute.d.ts +0 -128
  119. package/dist/runtime/execute.d.ts.map +0 -1
  120. package/dist/runtime/execute.js +0 -84
  121. package/dist/runtime/execute.js.map +0 -1
  122. package/dist/runtime/streaming-context.d.ts +0 -49
  123. package/dist/runtime/streaming-context.d.ts.map +0 -1
  124. package/dist/runtime/streaming-context.js +0 -71
  125. package/dist/runtime/streaming-context.js.map +0 -1
  126. package/dist/runtime/streaming-executor.d.ts +0 -159
  127. package/dist/runtime/streaming-executor.d.ts.map +0 -1
  128. package/dist/runtime/streaming-executor.js +0 -229
  129. package/dist/runtime/streaming-executor.js.map +0 -1
  130. package/src/api/streaming.test.ts +0 -433
  131. package/src/api/streaming.ts +0 -303
  132. package/src/runtime/execute.ts +0 -221
  133. package/src/runtime/streaming-context.ts +0 -164
  134. package/src/runtime/streaming-executor.ts +0 -367
@@ -1,433 +0,0 @@
1
- /**
2
- * Tests for streaming API definition.
3
- */
4
-
5
- import { describe, it, expect, vi } from "vitest";
6
- import { z } from "zod";
7
-
8
- import { postgres, anthropic } from "../integrations/declarations.js";
9
- import type { ApiContext } from "../types.js";
10
- import { api, __setEntryPoint } from "./definition.js";
11
- import { streamingApi, isStreamingApi } from "./streaming.js";
12
-
13
- describe("streamingApi()", () => {
14
- describe("basic creation", () => {
15
- it("creates a streaming API with input and chunk schemas", () => {
16
- const inputSchema = z.object({ prompt: z.string() });
17
- const chunkSchema = z.object({ text: z.string() });
18
-
19
- const streamingApiDef = streamingApi({
20
- name: "TestStreamingApi",
21
- input: inputSchema,
22
- chunk: chunkSchema,
23
- async *run() {
24
- yield { text: "Hello" };
25
- yield { text: " World" };
26
- },
27
- });
28
-
29
- expect(streamingApiDef.inputSchema).toBe(inputSchema);
30
- expect(streamingApiDef.chunkSchema).toBe(chunkSchema);
31
- expect(streamingApiDef.isStreaming).toBe(true);
32
- expect(typeof streamingApiDef.run).toBe("function");
33
- });
34
-
35
- it("creates a streaming API with integrations", () => {
36
- const inputSchema = z.object({ prompt: z.string() });
37
- const chunkSchema = z.object({ text: z.string() });
38
-
39
- const streamingApiDef = streamingApi({
40
- name: "TestStreamingApi",
41
- integrations: {
42
- ai: anthropic("Production Anthropic"),
43
- },
44
- input: inputSchema,
45
- chunk: chunkSchema,
46
- async *run() {
47
- yield { text: "test" };
48
- },
49
- });
50
-
51
- expect(streamingApiDef.integrations).toHaveLength(1);
52
- expect(streamingApiDef.integrations[0]).toMatchObject({
53
- key: "ai",
54
- pluginId: "anthropic",
55
- id: "Production Anthropic",
56
- });
57
- });
58
-
59
- it("has empty integrations array when none declared", () => {
60
- const streamingApiDef = streamingApi({
61
- name: "TestStreamingApi",
62
- input: z.object({ prompt: z.string() }),
63
- chunk: z.object({ text: z.string() }),
64
- async *run() {
65
- yield { text: "test" };
66
- },
67
- });
68
-
69
- expect(streamingApiDef.integrations).toEqual([]);
70
- });
71
- });
72
-
73
- describe("async generator execution", () => {
74
- it("run function returns an async iterable", async () => {
75
- const streamingApiDef = streamingApi({
76
- name: "TestStreamingApi",
77
- input: z.object({ prompt: z.string() }),
78
- chunk: z.object({ text: z.string() }),
79
- async *run() {
80
- yield { text: "Hello" };
81
- yield { text: " World" };
82
- },
83
- });
84
-
85
- const mockContext = {
86
- integrations: {} as Record<string, unknown>,
87
- log: {
88
- info: vi.fn(),
89
- warn: vi.fn(),
90
- error: vi.fn(),
91
- debug: vi.fn(),
92
- },
93
- env: {},
94
- };
95
-
96
- const iterator = streamingApiDef.run(
97
- mockContext as unknown as ApiContext<Record<string, never>>,
98
- { prompt: "test" },
99
- );
100
-
101
- expect(Symbol.asyncIterator in iterator).toBe(true);
102
-
103
- const chunks: { text: string }[] = [];
104
- for await (const chunk of iterator) {
105
- chunks.push(chunk);
106
- }
107
-
108
- expect(chunks).toEqual([{ text: "Hello" }, { text: " World" }]);
109
- });
110
-
111
- it("can access input in the run function", async () => {
112
- const inputCapture: string[] = [];
113
-
114
- const streamingApiDef = streamingApi({
115
- name: "TestStreamingApi",
116
- input: z.object({ prompt: z.string() }),
117
- chunk: z.object({ text: z.string() }),
118
- async *run(ctx, { prompt }) {
119
- inputCapture.push(prompt);
120
- yield { text: prompt };
121
- },
122
- });
123
-
124
- const mockContext = {
125
- integrations: {} as Record<string, unknown>,
126
- log: {
127
- info: vi.fn(),
128
- warn: vi.fn(),
129
- error: vi.fn(),
130
- debug: vi.fn(),
131
- },
132
- env: {},
133
- };
134
-
135
- const iterator = streamingApiDef.run(
136
- mockContext as unknown as ApiContext<Record<string, never>>,
137
- { prompt: "Hello, AI!" },
138
- );
139
- const chunks: { text: string }[] = [];
140
- for await (const chunk of iterator) {
141
- chunks.push(chunk);
142
- }
143
-
144
- expect(inputCapture).toEqual(["Hello, AI!"]);
145
- expect(chunks).toEqual([{ text: "Hello, AI!" }]);
146
- });
147
-
148
- it("yields multiple chunks over time", async () => {
149
- const streamingApiDef = streamingApi({
150
- name: "TestStreamingApi",
151
- input: z.object({ count: z.number() }),
152
- chunk: z.object({ index: z.number(), text: z.string() }),
153
- async *run(ctx, { count }) {
154
- for (let i = 0; i < count; i++) {
155
- yield { index: i, text: `Chunk ${i}` };
156
- }
157
- },
158
- });
159
-
160
- const mockContext = {
161
- integrations: {} as Record<string, unknown>,
162
- log: {
163
- info: vi.fn(),
164
- warn: vi.fn(),
165
- error: vi.fn(),
166
- debug: vi.fn(),
167
- },
168
- env: {},
169
- };
170
-
171
- const iterator = streamingApiDef.run(
172
- mockContext as unknown as ApiContext<Record<string, never>>,
173
- { count: 5 },
174
- );
175
- const chunks: { index: number; text: string }[] = [];
176
- for await (const chunk of iterator) {
177
- chunks.push(chunk);
178
- }
179
-
180
- expect(chunks).toHaveLength(5);
181
- expect(chunks[0]).toEqual({ index: 0, text: "Chunk 0" });
182
- expect(chunks[4]).toEqual({ index: 4, text: "Chunk 4" });
183
- });
184
- });
185
-
186
- describe("readonly properties", () => {
187
- it("inputSchema is readonly", () => {
188
- const streamingApiDef = streamingApi({
189
- name: "TestStreamingApi",
190
- input: z.object({ prompt: z.string() }),
191
- chunk: z.object({ text: z.string() }),
192
- async *run() {
193
- yield { text: "test" };
194
- },
195
- });
196
-
197
- expect(streamingApiDef.inputSchema).toBeDefined();
198
- });
199
-
200
- it("chunkSchema is readonly", () => {
201
- const streamingApiDef = streamingApi({
202
- name: "TestStreamingApi",
203
- input: z.object({ prompt: z.string() }),
204
- chunk: z.object({ text: z.string() }),
205
- async *run() {
206
- yield { text: "test" };
207
- },
208
- });
209
-
210
- expect(streamingApiDef.chunkSchema).toBeDefined();
211
- });
212
-
213
- it("isStreaming is always true", () => {
214
- const streamingApiDef = streamingApi({
215
- name: "TestStreamingApi",
216
- input: z.object({ prompt: z.string() }),
217
- chunk: z.object({ text: z.string() }),
218
- async *run() {
219
- yield { text: "test" };
220
- },
221
- });
222
-
223
- expect(streamingApiDef.isStreaming).toBe(true);
224
- });
225
- });
226
- });
227
-
228
- describe("isStreamingApi()", () => {
229
- describe("with streaming APIs", () => {
230
- it("returns true for streaming API", () => {
231
- const streamingApiDef = streamingApi({
232
- name: "TestStreamingApi",
233
- input: z.object({ prompt: z.string() }),
234
- chunk: z.object({ text: z.string() }),
235
- async *run() {
236
- yield { text: "test" };
237
- },
238
- });
239
-
240
- expect(isStreamingApi(streamingApiDef)).toBe(true);
241
- });
242
- });
243
-
244
- describe("with regular APIs", () => {
245
- it("returns false for regular API", () => {
246
- const regularApi = api({
247
- name: "RegularApi",
248
- input: z.object({ userId: z.string() }),
249
- output: z.object({ name: z.string() }),
250
- async run() {
251
- return { name: "Test" };
252
- },
253
- });
254
-
255
- expect(isStreamingApi(regularApi)).toBe(false);
256
- });
257
- });
258
-
259
- describe("with non-API values", () => {
260
- it("returns false for null", () => {
261
- expect(isStreamingApi(null)).toBe(false);
262
- });
263
-
264
- it("returns false for undefined", () => {
265
- expect(isStreamingApi(undefined)).toBe(false);
266
- });
267
-
268
- it("returns false for plain object", () => {
269
- expect(isStreamingApi({ isStreaming: false })).toBe(false);
270
- });
271
-
272
- it("returns false for number", () => {
273
- expect(isStreamingApi(42)).toBe(false);
274
- });
275
-
276
- it("returns false for string", () => {
277
- expect(isStreamingApi("streaming")).toBe(false);
278
- });
279
-
280
- it("returns false for object without isStreaming property", () => {
281
- expect(isStreamingApi({ inputSchema: z.string() })).toBe(false);
282
- });
283
-
284
- it("returns false for object with only isStreaming true but missing required fields", () => {
285
- expect(isStreamingApi({ isStreaming: true })).toBe(false);
286
- });
287
-
288
- it("returns true for object with isStreaming true and all required fields", () => {
289
- expect(
290
- isStreamingApi({
291
- isStreaming: true,
292
- inputSchema: z.string(),
293
- chunkSchema: z.string(),
294
- run: () => {},
295
- }),
296
- ).toBe(true);
297
- });
298
- });
299
- });
300
-
301
- describe("type inference", () => {
302
- it("infers input type from schema", () => {
303
- const streamingApiDef = streamingApi({
304
- name: "TestStreamingApi",
305
- input: z.object({
306
- prompt: z.string(),
307
- maxTokens: z.number().optional(),
308
- }),
309
- chunk: z.object({ text: z.string() }),
310
- async *run(ctx, { prompt, maxTokens }) {
311
- const p: string = prompt;
312
- const m: number | undefined = maxTokens;
313
- yield { text: `${p} ${m ?? 100}` };
314
- },
315
- });
316
-
317
- expect(streamingApiDef).toBeDefined();
318
- });
319
-
320
- it("infers chunk type from schema", () => {
321
- const streamingApiDef = streamingApi({
322
- name: "TestStreamingApi",
323
- input: z.object({ prompt: z.string() }),
324
- chunk: z.object({
325
- type: z.literal("text-delta"),
326
- text: z.string(),
327
- index: z.number(),
328
- }),
329
- async *run() {
330
- yield {
331
- type: "text-delta" as const,
332
- text: "Hello",
333
- index: 0,
334
- };
335
- },
336
- });
337
-
338
- expect(streamingApiDef.chunkSchema).toBeDefined();
339
- });
340
-
341
- it("infers integration types", () => {
342
- const streamingApiDef = streamingApi({
343
- name: "TestStreamingApi",
344
- integrations: {
345
- ai: anthropic("AI Service"),
346
- db: postgres("Database"),
347
- },
348
- input: z.object({ prompt: z.string() }),
349
- chunk: z.object({ text: z.string() }),
350
- async *run() {
351
- yield { text: "test" };
352
- },
353
- });
354
-
355
- expect(streamingApiDef.integrations).toHaveLength(2);
356
- });
357
- });
358
-
359
- describe("entryPoint mechanism", () => {
360
- it("streamingApi() has no entryPoint when __setEntryPoint was not called", () => {
361
- const compiled = streamingApi({
362
- name: "NoEntryPoint",
363
- input: z.object({}),
364
- chunk: z.object({ text: z.string() }),
365
- async *run() {
366
- yield { text: "hello" };
367
- },
368
- });
369
-
370
- expect(compiled.entryPoint).toBeUndefined();
371
- });
372
-
373
- it("streamingApi() picks up entryPoint set via __setEntryPoint", () => {
374
- __setEntryPoint("server/apis/Chat/api.ts");
375
- const compiled = streamingApi({
376
- name: "Chat",
377
- input: z.object({ prompt: z.string() }),
378
- chunk: z.object({ text: z.string() }),
379
- async *run() {
380
- yield { text: "hello" };
381
- },
382
- });
383
-
384
- expect(compiled.entryPoint).toBe("server/apis/Chat/api.ts");
385
- });
386
-
387
- it("entryPoint is consumed once — second streamingApi() call gets undefined", () => {
388
- __setEntryPoint("server/apis/Stream/api.ts");
389
- const first = streamingApi({
390
- name: "Stream",
391
- input: z.object({}),
392
- chunk: z.object({ text: z.string() }),
393
- async *run() {
394
- yield { text: "a" };
395
- },
396
- });
397
- const second = streamingApi({
398
- name: "Stream2",
399
- input: z.object({}),
400
- chunk: z.object({ text: z.string() }),
401
- async *run() {
402
- yield { text: "b" };
403
- },
404
- });
405
-
406
- expect(first.entryPoint).toBe("server/apis/Stream/api.ts");
407
- expect(second.entryPoint).toBeUndefined();
408
- });
409
-
410
- it("__setEntryPoint works across api() and streamingApi()", () => {
411
- __setEntryPoint("server/apis/Mixed/api.ts");
412
- const compiled = streamingApi({
413
- name: "Mixed",
414
- input: z.object({}),
415
- chunk: z.object({ text: z.string() }),
416
- async *run() {
417
- yield { text: "mixed" };
418
- },
419
- });
420
-
421
- expect(compiled.entryPoint).toBe("server/apis/Mixed/api.ts");
422
-
423
- const afterConsume = api({
424
- name: "After",
425
- input: z.object({}),
426
- output: z.object({}),
427
- async run() {
428
- return {};
429
- },
430
- });
431
- expect(afterConsume.entryPoint).toBeUndefined();
432
- });
433
- });