@mcpc-tech/core 0.2.7-beta.2 → 0.2.8
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/index.mjs +27 -40
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2159,29 +2159,19 @@ var BaseSamplingExecutor = class {
|
|
|
2159
2159
|
}
|
|
2160
2160
|
});
|
|
2161
2161
|
const action = parsedData["action"];
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2164
|
-
iterationSpan = this.tracingEnabled ? startSpan(spanName, {
|
|
2165
|
-
iteration: this.currentIteration + 1,
|
|
2166
|
-
agent: this.name,
|
|
2167
|
-
action: actionStr,
|
|
2168
|
-
systemPrompt: systemPrompt(),
|
|
2169
|
-
maxTokens: String(Number.MAX_SAFE_INTEGER),
|
|
2170
|
-
maxIterations: this.maxIterations,
|
|
2171
|
-
messages: JSON.stringify(this.conversationHistory)
|
|
2172
|
-
}, loopSpan ?? void 0) : null;
|
|
2173
|
-
if (!action || typeof parsedData["decision"] !== "string") {
|
|
2162
|
+
const decision = parsedData["decision"];
|
|
2163
|
+
if (typeof decision !== "string") {
|
|
2174
2164
|
this.conversationHistory.push({
|
|
2175
2165
|
role: "user",
|
|
2176
2166
|
content: {
|
|
2177
2167
|
type: "text",
|
|
2178
|
-
text: '
|
|
2168
|
+
text: 'Missing required field "decision". Provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}} or {"decision":"complete"}'
|
|
2179
2169
|
}
|
|
2180
2170
|
});
|
|
2181
2171
|
if (iterationSpan) endSpan(iterationSpan);
|
|
2182
2172
|
continue;
|
|
2183
2173
|
}
|
|
2184
|
-
if (
|
|
2174
|
+
if (decision === "complete" && action) {
|
|
2185
2175
|
this.conversationHistory.push({
|
|
2186
2176
|
role: "user",
|
|
2187
2177
|
content: {
|
|
@@ -2192,6 +2182,28 @@ var BaseSamplingExecutor = class {
|
|
|
2192
2182
|
if (iterationSpan) endSpan(iterationSpan);
|
|
2193
2183
|
continue;
|
|
2194
2184
|
}
|
|
2185
|
+
if (decision !== "complete" && !action) {
|
|
2186
|
+
this.conversationHistory.push({
|
|
2187
|
+
role: "user",
|
|
2188
|
+
content: {
|
|
2189
|
+
type: "text",
|
|
2190
|
+
text: 'Missing required field "action". When executing, provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}}'
|
|
2191
|
+
}
|
|
2192
|
+
});
|
|
2193
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2194
|
+
continue;
|
|
2195
|
+
}
|
|
2196
|
+
const actionStr = decision === "complete" ? "completion" : action && typeof action === "string" ? String(action) : "unknown_action";
|
|
2197
|
+
const spanName = `mcpc.sampling_iteration.${actionStr}`;
|
|
2198
|
+
iterationSpan = this.tracingEnabled ? startSpan(spanName, {
|
|
2199
|
+
iteration: this.currentIteration + 1,
|
|
2200
|
+
agent: this.name,
|
|
2201
|
+
action: actionStr,
|
|
2202
|
+
systemPrompt: systemPrompt(),
|
|
2203
|
+
maxTokens: String(Number.MAX_SAFE_INTEGER),
|
|
2204
|
+
maxIterations: this.maxIterations,
|
|
2205
|
+
messages: JSON.stringify(this.conversationHistory)
|
|
2206
|
+
}, loopSpan ?? void 0) : null;
|
|
2195
2207
|
const result = await this.processAction(parsedData, schema, state, iterationSpan);
|
|
2196
2208
|
this.logIterationProgress(parsedData, result, model, stopReason, role);
|
|
2197
2209
|
if (iterationSpan) {
|
|
@@ -2207,6 +2219,7 @@ var BaseSamplingExecutor = class {
|
|
|
2207
2219
|
maxIterations: this.maxIterations,
|
|
2208
2220
|
parsed: rawJson,
|
|
2209
2221
|
action: typeof action === "string" ? action : String(action),
|
|
2222
|
+
decision: typeof decision === "string" ? decision : String(decision),
|
|
2210
2223
|
samplingResponse: responseContent,
|
|
2211
2224
|
toolResult: JSON.stringify(result),
|
|
2212
2225
|
model,
|
|
@@ -2472,19 +2485,6 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
2472
2485
|
}
|
|
2473
2486
|
async processAction(parsedData, schema, _state, parentSpan) {
|
|
2474
2487
|
const toolCallData = parsedData;
|
|
2475
|
-
const isComplete = toolCallData.decision === "complete";
|
|
2476
|
-
const actionName = toolCallData.action;
|
|
2477
|
-
if (isComplete && actionName) {
|
|
2478
|
-
return {
|
|
2479
|
-
content: [
|
|
2480
|
-
{
|
|
2481
|
-
type: "text",
|
|
2482
|
-
text: 'Invalid: Cannot have both "decision":"complete" and "action" field. When complete, only provide {"decision":"complete"}. When executing, provide {"action":"<tool>","decision":"proceed|retry","<tool>":{}}.'
|
|
2483
|
-
}
|
|
2484
|
-
],
|
|
2485
|
-
isError: true
|
|
2486
|
-
};
|
|
2487
|
-
}
|
|
2488
2488
|
if (toolCallData.decision === "complete") {
|
|
2489
2489
|
return await this.createCompletionResult("Task completed", parentSpan);
|
|
2490
2490
|
}
|
|
@@ -3104,19 +3104,6 @@ var WorkflowSamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
3104
3104
|
throw new Error("WorkflowState is required for workflow");
|
|
3105
3105
|
}
|
|
3106
3106
|
const toolCallData = parsedData;
|
|
3107
|
-
const isComplete = toolCallData.decision === "complete";
|
|
3108
|
-
const actionName = toolCallData.action;
|
|
3109
|
-
if (isComplete && actionName) {
|
|
3110
|
-
return {
|
|
3111
|
-
content: [
|
|
3112
|
-
{
|
|
3113
|
-
type: "text",
|
|
3114
|
-
text: 'Invalid: Cannot have both "decision":"complete" and "action" field. When complete, only provide {"decision":"complete"}. When executing, provide {"action":"<tool>","decision":"proceed|retry","<tool>":{}}.'
|
|
3115
|
-
}
|
|
3116
|
-
],
|
|
3117
|
-
isError: true
|
|
3118
|
-
};
|
|
3119
|
-
}
|
|
3120
3107
|
if (toolCallData.decision === "complete") {
|
|
3121
3108
|
return await this.createCompletionResult("Task completed", parentSpan);
|
|
3122
3109
|
}
|