@love-moon/ai-sdk 0.2.37 → 0.2.39

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/dist/worker.js CHANGED
@@ -85,6 +85,24 @@ async function handleRequest(message) {
85
85
  process.exit(0);
86
86
  }
87
87
  }
88
+ async function dispatchMessage(message) {
89
+ try {
90
+ if (message?.type === "create") {
91
+ await handleCreate(message);
92
+ return;
93
+ }
94
+ if (message?.type === "request" || message?.type === "control") {
95
+ await handleRequest(message);
96
+ }
97
+ }
98
+ catch (error) {
99
+ send({
100
+ type: message?.type === "create" ? "create_error" : "response",
101
+ id: message?.id,
102
+ error: serializeError(error),
103
+ });
104
+ }
105
+ }
88
106
  async function closeSession() {
89
107
  if (!session || typeof session.close !== "function") {
90
108
  return;
@@ -121,42 +139,31 @@ process.stdin.on("end", async () => {
121
139
  const input = readline.createInterface({ input: process.stdin });
122
140
  let workQueue = Promise.resolve();
123
141
  input.on("line", (line) => {
142
+ const normalized = String(line || "").trim();
143
+ if (!normalized) {
144
+ return;
145
+ }
146
+ let message;
147
+ try {
148
+ message = JSON.parse(normalized);
149
+ }
150
+ catch (error) {
151
+ send({
152
+ type: "event",
153
+ name: "worker_error",
154
+ payload: serializeError(error),
155
+ });
156
+ return;
157
+ }
158
+ if (message?.type === "control") {
159
+ void dispatchMessage(message);
160
+ return;
161
+ }
124
162
  workQueue = workQueue
125
163
  .catch(() => {
126
164
  // keep queue alive after previous failure
127
165
  })
128
166
  .then(async () => {
129
- const normalized = String(line || "").trim();
130
- if (!normalized) {
131
- return;
132
- }
133
- let message;
134
- try {
135
- message = JSON.parse(normalized);
136
- }
137
- catch (error) {
138
- send({
139
- type: "event",
140
- name: "worker_error",
141
- payload: serializeError(error),
142
- });
143
- return;
144
- }
145
- try {
146
- if (message?.type === "create") {
147
- await handleCreate(message);
148
- return;
149
- }
150
- if (message?.type === "request") {
151
- await handleRequest(message);
152
- }
153
- }
154
- catch (error) {
155
- send({
156
- type: message?.type === "create" ? "create_error" : "response",
157
- id: message?.id,
158
- error: serializeError(error),
159
- });
160
- }
167
+ await dispatchMessage(message);
161
168
  });
162
169
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@love-moon/ai-sdk",
3
- "version": "0.2.37",
3
+ "version": "0.2.39",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,5 +25,5 @@
25
25
  "@types/node": "^22.10.2",
26
26
  "typescript": "^5.6.3"
27
27
  },
28
- "gitCommitId": "c656a7d"
28
+ "gitCommitId": "30204c8"
29
29
  }