@302ai/media-studio-core 0.1.0-beta.0 → 0.1.0-beta.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.
@@ -122,6 +122,8 @@ export class ClientSessions {
122
122
  signal,
123
123
  });
124
124
  if (!response.ok) {
125
+ // Release the body so pooled connections stay reusable.
126
+ await response.body?.cancel().catch(() => undefined);
125
127
  // 4xx (except 429) is deterministic: no point retrying.
126
128
  const retryable = response.status >= 500 || response.status === 429;
127
129
  if (!retryable)
@@ -200,13 +202,20 @@ export class ClientSessions {
200
202
  });
201
203
  const reader = response.body.getReader();
202
204
  const decoder = new TextDecoder();
203
- for (;;) {
204
- const { done, value } = await reader.read();
205
- if (done)
206
- break;
207
- parser.feed(decoder.decode(value, { stream: true }));
208
- if (state.outcome)
209
- break;
205
+ try {
206
+ for (;;) {
207
+ const { done, value } = await reader.read();
208
+ if (done)
209
+ break;
210
+ parser.feed(decoder.decode(value, { stream: true }));
211
+ if (state.outcome)
212
+ break;
213
+ }
214
+ }
215
+ finally {
216
+ // Terminal event or EOF: release the connection even if upstream keeps
217
+ // the SSE stream open. Cancel may reject when the stream already errored.
218
+ await reader.cancel().catch(() => undefined);
210
219
  }
211
220
  parser.feed(decoder.decode());
212
221
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@302ai/media-studio-core",
3
- "version": "0.1.0-beta.0",
3
+ "version": "0.1.0-beta.1",
4
4
  "description": "Outbound client for the 302.AI media-studio async chat completions SSE endpoint",
5
5
  "author": "302.AI",
6
6
  "license": "Apache-2.0",
package/dist/events.d.ts DELETED
@@ -1,90 +0,0 @@
1
- import { z } from "zod";
2
- /** Text part delta in streaming turn. */
3
- export declare const TextDeltaEventSchema: z.ZodObject<{
4
- type: z.ZodLiteral<"text-delta">;
5
- delta: z.ZodString;
6
- id: z.ZodOptional<z.ZodString>;
7
- }, z.core.$strip>;
8
- /** Reasoning / thinking part delta in streaming turn. */
9
- export declare const ReasoningDeltaEventSchema: z.ZodObject<{
10
- type: z.ZodLiteral<"reasoning-delta">;
11
- delta: z.ZodString;
12
- id: z.ZodOptional<z.ZodString>;
13
- }, z.core.$strip>;
14
- /** Tool invocation event emitted when assistant calls an external tool. */
15
- export declare const ToolCallEventSchema: z.ZodObject<{
16
- type: z.ZodLiteral<"tool-call">;
17
- toolCallId: z.ZodString;
18
- toolName: z.ZodString;
19
- args: z.ZodOptional<z.ZodUnknown>;
20
- }, z.core.$strip>;
21
- /** Tool result response emitted after tool execution finishes. */
22
- export declare const ToolResultEventSchema: z.ZodObject<{
23
- type: z.ZodLiteral<"tool-result">;
24
- toolCallId: z.ZodString;
25
- result: z.ZodOptional<z.ZodUnknown>;
26
- }, z.core.$strip>;
27
- /** High-level media result event emitted when image/video generation completes. */
28
- export declare const MediaResultEventSchema: z.ZodObject<{
29
- type: z.ZodLiteral<"media-result">;
30
- result: z.ZodObject<{
31
- status: z.ZodOptional<z.ZodString>;
32
- domain: z.ZodOptional<z.ZodString>;
33
- operation: z.ZodOptional<z.ZodString>;
34
- modelUsed: z.ZodOptional<z.ZodString>;
35
- taskId: z.ZodOptional<z.ZodString>;
36
- resultUrl: z.ZodOptional<z.ZodString>;
37
- prompt: z.ZodOptional<z.ZodString>;
38
- }, z.core.$strip>;
39
- }, z.core.$strip>;
40
- /** Terminal finish event indicating turn completion. */
41
- export declare const FinishEventSchema: z.ZodObject<{
42
- type: z.ZodLiteral<"finish">;
43
- finishReason: z.ZodOptional<z.ZodString>;
44
- }, z.core.$strip>;
45
- /** Stream error event. Supports either error or message string. */
46
- export declare const StreamErrorEventSchema: z.ZodObject<{
47
- type: z.ZodLiteral<"error">;
48
- error: z.ZodOptional<z.ZodString>;
49
- message: z.ZodOptional<z.ZodString>;
50
- chatTaskId: z.ZodOptional<z.ZodString>;
51
- }, z.core.$strip>;
52
- /** Discriminated union of all possible streaming events yielded by ChatStream. */
53
- export declare const ChatStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
54
- type: z.ZodLiteral<"text-delta">;
55
- delta: z.ZodString;
56
- id: z.ZodOptional<z.ZodString>;
57
- }, z.core.$strip>, z.ZodObject<{
58
- type: z.ZodLiteral<"reasoning-delta">;
59
- delta: z.ZodString;
60
- id: z.ZodOptional<z.ZodString>;
61
- }, z.core.$strip>, z.ZodObject<{
62
- type: z.ZodLiteral<"tool-call">;
63
- toolCallId: z.ZodString;
64
- toolName: z.ZodString;
65
- args: z.ZodOptional<z.ZodUnknown>;
66
- }, z.core.$strip>, z.ZodObject<{
67
- type: z.ZodLiteral<"tool-result">;
68
- toolCallId: z.ZodString;
69
- result: z.ZodOptional<z.ZodUnknown>;
70
- }, z.core.$strip>, z.ZodObject<{
71
- type: z.ZodLiteral<"media-result">;
72
- result: z.ZodObject<{
73
- status: z.ZodOptional<z.ZodString>;
74
- domain: z.ZodOptional<z.ZodString>;
75
- operation: z.ZodOptional<z.ZodString>;
76
- modelUsed: z.ZodOptional<z.ZodString>;
77
- taskId: z.ZodOptional<z.ZodString>;
78
- resultUrl: z.ZodOptional<z.ZodString>;
79
- prompt: z.ZodOptional<z.ZodString>;
80
- }, z.core.$strip>;
81
- }, z.core.$strip>, z.ZodObject<{
82
- type: z.ZodLiteral<"finish">;
83
- finishReason: z.ZodOptional<z.ZodString>;
84
- }, z.core.$strip>, z.ZodObject<{
85
- type: z.ZodLiteral<"error">;
86
- error: z.ZodOptional<z.ZodString>;
87
- message: z.ZodOptional<z.ZodString>;
88
- chatTaskId: z.ZodOptional<z.ZodString>;
89
- }, z.core.$strip>], "type">;
90
- export type ChatStreamEvent = z.infer<typeof ChatStreamEventSchema>;
package/dist/media.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { z } from "zod";
2
- export declare const MediaResultSchema: z.ZodObject<{
3
- status: z.ZodOptional<z.ZodString>;
4
- domain: z.ZodOptional<z.ZodString>;
5
- operation: z.ZodOptional<z.ZodString>;
6
- modelUsed: z.ZodOptional<z.ZodString>;
7
- taskId: z.ZodOptional<z.ZodString>;
8
- resultUrl: z.ZodOptional<z.ZodString>;
9
- prompt: z.ZodOptional<z.ZodString>;
10
- }, z.core.$strip>;
11
- export type MediaResult = z.infer<typeof MediaResultSchema>;
12
- /**
13
- * Extracts a structured media result from a tool output string. Returns null unless
14
- * the output contains media task completion identifiers (`task_id` or `result_url`).
15
- */
16
- export declare function extractMediaResult(output: unknown): MediaResult | null;