@gobing-ai/ts-ai-decision 0.8.1 → 0.8.2

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.
@@ -26,7 +26,7 @@ export function createTypesafeDriver(config) {
26
26
  defaultModel: config.model,
27
27
  timeout: config.timeoutMs,
28
28
  retry: config.maxRetries === undefined ? undefined : { maxRetries: config.maxRetries },
29
- fetch: config.fetch,
29
+ fetch: streamBackedFetch(config.fetch ?? fetch),
30
30
  });
31
31
  }
32
32
  catch (err) {
@@ -61,6 +61,30 @@ export function createTypesafeDriver(config) {
61
61
  },
62
62
  };
63
63
  }
64
+ /**
65
+ * SDK 0.7.0's `bufferResponse` takes a reader on the original body and releases it, then
66
+ * `parseBody` calls `res.text()`. On Bun, a response whose body is already buffered (as a real
67
+ * fetch reply often is) counts as disturbed after that, so every call threw
68
+ * `TypeError: Body already used`. Re-emitting the bytes as a fresh stream gives the SDK the
69
+ * stream-backed body it expects. The read runs inside the SDK's attempt, so its timeout and abort
70
+ * still apply. ponytail: drop once the SDK stops locking the original body.
71
+ */
72
+ function streamBackedFetch(base) {
73
+ return (async (input, init) => {
74
+ const res = await base(input, init);
75
+ if (res.body === null)
76
+ return res;
77
+ const bytes = new Uint8Array(await res.arrayBuffer());
78
+ const body = new ReadableStream({
79
+ start(controller) {
80
+ if (bytes.byteLength > 0)
81
+ controller.enqueue(bytes);
82
+ controller.close();
83
+ },
84
+ });
85
+ return new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
86
+ });
87
+ }
64
88
  /** Neutral question → SDK wire question (R4). `null` is "undescribed" on the wire. */
65
89
  function toSdkQuestion(question) {
66
90
  switch (question.kind) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobing-ai/ts-ai-decision",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "@gobing-ai/ts-ai-decision — Declarative YAML decision catalog over the ts-ai-runner DecisionMaker surface.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -51,17 +51,17 @@
51
51
  "release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-ai-decision-v<version> && git push --tags' && exit 1"
52
52
  },
53
53
  "dependencies": {
54
- "@gobing-ai/ts-ai-runner": "^0.8.1",
55
- "@gobing-ai/ts-decision-fm": "^0.8.1",
56
- "@gobing-ai/ts-runtime": "^0.8.1",
54
+ "@gobing-ai/ts-ai-runner": "^0.8.2",
55
+ "@gobing-ai/ts-decision-fm": "^0.8.2",
56
+ "@gobing-ai/ts-runtime": "^0.8.2",
57
57
  "@typesafe-ai/sdk": "0.7.0",
58
58
  "zod": "^4.1.0"
59
59
  },
60
60
  "optionalDependencies": {
61
- "@gobing-ai/ts-laya-mlx": "^0.8.1"
61
+ "@gobing-ai/ts-laya-mlx": "^0.8.2"
62
62
  },
63
63
  "devDependencies": {
64
- "@gobing-ai/ts-utils": "^0.8.1",
64
+ "@gobing-ai/ts-utils": "^0.8.2",
65
65
  "@types/bun": "1.4.3"
66
66
  },
67
67
  "publishConfig": {
@@ -69,7 +69,7 @@ export function createTypesafeDriver(config: TypesafeDriverConfig): DecisionDriv
69
69
  defaultModel: config.model,
70
70
  timeout: config.timeoutMs,
71
71
  retry: config.maxRetries === undefined ? undefined : { maxRetries: config.maxRetries },
72
- fetch: config.fetch,
72
+ fetch: streamBackedFetch(config.fetch ?? fetch),
73
73
  });
74
74
  } catch (err) {
75
75
  translateError(err);
@@ -110,6 +110,29 @@ export function createTypesafeDriver(config: TypesafeDriverConfig): DecisionDriv
110
110
  };
111
111
  }
112
112
 
113
+ /**
114
+ * SDK 0.7.0's `bufferResponse` takes a reader on the original body and releases it, then
115
+ * `parseBody` calls `res.text()`. On Bun, a response whose body is already buffered (as a real
116
+ * fetch reply often is) counts as disturbed after that, so every call threw
117
+ * `TypeError: Body already used`. Re-emitting the bytes as a fresh stream gives the SDK the
118
+ * stream-backed body it expects. The read runs inside the SDK's attempt, so its timeout and abort
119
+ * still apply. ponytail: drop once the SDK stops locking the original body.
120
+ */
121
+ function streamBackedFetch(base: typeof fetch): typeof fetch {
122
+ return (async (input: Parameters<typeof fetch>[0], init?: RequestInit) => {
123
+ const res = await base(input, init);
124
+ if (res.body === null) return res;
125
+ const bytes = new Uint8Array(await res.arrayBuffer());
126
+ const body = new ReadableStream<Uint8Array>({
127
+ start(controller) {
128
+ if (bytes.byteLength > 0) controller.enqueue(bytes);
129
+ controller.close();
130
+ },
131
+ });
132
+ return new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
133
+ }) as typeof fetch;
134
+ }
135
+
113
136
  /** Neutral question → SDK wire question (R4). `null` is "undescribed" on the wire. */
114
137
  function toSdkQuestion(question: Question): SdkQuestion {
115
138
  switch (question.kind) {