@ryanfw/prompt-orchestration-pipeline 0.9.0 → 0.9.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.
- package/package.json +1 -1
- package/src/core/task-runner.js +34 -1
- package/src/providers/zhipu.js +32 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryanfw/prompt-orchestration-pipeline",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "A Prompt-orchestration pipeline (POP) is a framework for building, running, and experimenting with complex chains of LLM tasks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/ui/server.js",
|
package/src/core/task-runner.js
CHANGED
|
@@ -855,8 +855,41 @@ function toAbsFileURL(p) {
|
|
|
855
855
|
}
|
|
856
856
|
|
|
857
857
|
function normalizeError(err) {
|
|
858
|
-
if (err instanceof Error)
|
|
858
|
+
if (err instanceof Error) {
|
|
859
859
|
return { name: err.name, message: err.message, stack: err.stack };
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// Handle plain object errors (like those from HTTP responses)
|
|
863
|
+
if (typeof err === "object" && err !== null) {
|
|
864
|
+
let message = "Unknown error";
|
|
865
|
+
if (typeof err?.message === "string") {
|
|
866
|
+
message = err.message;
|
|
867
|
+
} else if (typeof err?.error?.message === "string") {
|
|
868
|
+
message = err.error.message;
|
|
869
|
+
} else if (typeof err?.error === "string") {
|
|
870
|
+
message = err.error;
|
|
871
|
+
}
|
|
872
|
+
const result = { message };
|
|
873
|
+
|
|
874
|
+
// Include additional context if available
|
|
875
|
+
if (err.status) result.status = err.status;
|
|
876
|
+
if (err.code) result.code = err.code;
|
|
877
|
+
if (err.error) {
|
|
878
|
+
if (typeof err.error === "string") {
|
|
879
|
+
result.error = err.error;
|
|
880
|
+
} else if (typeof err.error === "object" && err.error !== null) {
|
|
881
|
+
// Try to extract a message property, else serialize the object
|
|
882
|
+
result.error = err.error.message
|
|
883
|
+
? err.error.message
|
|
884
|
+
: JSON.stringify(err.error);
|
|
885
|
+
} else {
|
|
886
|
+
result.error = String(err.error);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
return result;
|
|
891
|
+
}
|
|
892
|
+
|
|
860
893
|
return { message: String(err) };
|
|
861
894
|
}
|
|
862
895
|
|
package/src/providers/zhipu.js
CHANGED
|
@@ -65,20 +65,39 @@ export async function zhipuChat({
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
console.log("[Zhipu] Calling Zhipu API...");
|
|
68
|
-
const response = await fetch(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
const response = await fetch(
|
|
69
|
+
"https://api.z.ai/api/paas/v4/chat/completions",
|
|
70
|
+
{
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: {
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
Authorization: `Bearer ${process.env.ZHIPU_API_KEY}`,
|
|
75
|
+
},
|
|
76
|
+
body: JSON.stringify(requestBody),
|
|
77
|
+
}
|
|
78
|
+
);
|
|
76
79
|
|
|
77
80
|
if (!response.ok) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
let errorMessage;
|
|
82
|
+
try {
|
|
83
|
+
const errorData = await response.json();
|
|
84
|
+
errorMessage =
|
|
85
|
+
errorData?.error?.message ||
|
|
86
|
+
errorData?.message ||
|
|
87
|
+
response.statusText ||
|
|
88
|
+
"Unknown error";
|
|
89
|
+
} catch {
|
|
90
|
+
// If JSON parsing fails, try to get text response
|
|
91
|
+
try {
|
|
92
|
+
errorMessage = await response.text();
|
|
93
|
+
} catch {
|
|
94
|
+
errorMessage = response.statusText || "Unknown error";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const error = new Error(errorMessage);
|
|
99
|
+
error.status = response.status;
|
|
100
|
+
throw error;
|
|
82
101
|
}
|
|
83
102
|
|
|
84
103
|
const data = await response.json();
|
|
@@ -117,7 +136,7 @@ export async function zhipuChat({
|
|
|
117
136
|
};
|
|
118
137
|
} catch (error) {
|
|
119
138
|
lastError = error;
|
|
120
|
-
const msg = error?.
|
|
139
|
+
const msg = error?.message || error?.toString() || "Unknown error";
|
|
121
140
|
console.error("[Zhipu] Error occurred:", msg);
|
|
122
141
|
console.error("[Zhipu] Error status:", error?.status);
|
|
123
142
|
|