@kingsoftcloud/agentkit-harness-core 0.0.26 → 0.0.28
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/machine.mjs +18 -6
- package/dist/model-failure.d.mts +1 -1
- package/dist/model-failure.mjs +1 -0
- package/dist/model-json.mjs +16 -6
- package/package.json +1 -1
- package/src/machine.mts +17 -6
- package/src/model-failure.mts +1 -0
- package/src/model-json.mts +14 -6
package/dist/machine.mjs
CHANGED
|
@@ -314,6 +314,8 @@ export function validateModelResult(input) {
|
|
|
314
314
|
invariant(!failure || ['provider_terminal_error', 'provider_retryable_error', 'policy_abort', 'malformed_tool_call'].includes(result.kind)
|
|
315
315
|
|| result.kind === 'output_limit' && result.outputBoundary === 'no-visible-output/v1'
|
|
316
316
|
&& failure.phase === 'stream' && failure.code === 'reasoning_repetition'
|
|
317
|
+
|| result.kind === 'output_limit' && failure.phase === 'stream'
|
|
318
|
+
&& ['stream_frame_limit', 'stream_output_limit'].includes(failure.code)
|
|
317
319
|
|| result.kind === 'context_overflow' && failure.httpStatus === 400
|
|
318
320
|
&& (failure.gateway?.code === 'context_length_exceeded' || failure.gateway?.type === 'context_length_exceeded'), 'model_failure_diagnostic_requires_failure');
|
|
319
321
|
invariant(['tool_calls', 'final_candidate', 'output_limit', 'context_overflow', 'empty_response', 'malformed_tool_call',
|
|
@@ -496,7 +498,7 @@ export function reduceModel(snapshot, input, config, now, random, digest = canon
|
|
|
496
498
|
: result.text ? 'The last response hit its output limit. Return only the exact missing suffix of that response. '
|
|
497
499
|
+ (responseBoundaryRecovery(config) ? 'You may replay the final incomplete line verbatim before continuing; the Host joins this exact overlap. Do not replay any complete line. ' : '')
|
|
498
500
|
+ 'Incomplete tool calls were not executed.'
|
|
499
|
-
: 'The last response hit its output limit without visible content or a committed tool call. Continue
|
|
501
|
+
: 'The last response hit its output limit without visible content or a committed tool call. Continue from the last committed state in smaller steps; answer only if the task is complete.' }];
|
|
500
502
|
return { mode, messages };
|
|
501
503
|
};
|
|
502
504
|
const exhausted = () => resumable
|
|
@@ -548,19 +550,29 @@ export function reduceModel(snapshot, input, config, now, random, digest = canon
|
|
|
548
550
|
case 'provider_retryable_error': {
|
|
549
551
|
const provider = result.kind === 'provider_retryable_error';
|
|
550
552
|
const attempts = (provider ? snapshot.providerErrors : snapshot.modelErrors) + 1;
|
|
551
|
-
const
|
|
553
|
+
const oversizedTool = result.kind === 'malformed_tool_call' && result.failureDiagnostic?.code === 'tool_argument_limit';
|
|
554
|
+
const limit = provider ? config.profile.maxProviderRetries
|
|
555
|
+
: oversizedTool ? Math.min(config.profile.maxRetries, 1) : config.profile.maxRetries;
|
|
556
|
+
const exhausted = attempts > limit;
|
|
552
557
|
const delay = retryDelay(result, attempts, config, random);
|
|
553
558
|
// An unavailable provider is not a task failure: pause with a fresh budget so the Host can resume later.
|
|
554
559
|
if (provider && exhausted && config.providerRecoveryPolicy === 'provider-recovery/v2')
|
|
555
560
|
return { ...base, phase: 'paused',
|
|
556
561
|
resumePhase: 'preparing_context', outcome: null, reason: 'provider_unavailable', providerErrors: 0, retryNotBefore: 0 };
|
|
562
|
+
const messages = provider ? snapshot.messages : [...snapshot.messages, { role: 'user', kind: responseContinuationPending(snapshot, config)
|
|
563
|
+
? 'response_continuation_feedback' : 'model_feedback',
|
|
564
|
+
content: oversizedTool
|
|
565
|
+
? 'The last tool batch exceeded the tool input size limit and was not executed. Continue the task with smaller tool calls, splitting large file changes into separate edits. Keep all earlier tool results.'
|
|
566
|
+
: result.kind === 'empty_response' ? 'The last response was empty. Continue the task or provide a complete answer.'
|
|
567
|
+
: 'The last tool call was malformed and was not executed. Return complete valid tool arguments.' }];
|
|
568
|
+
if (oversizedTool && exhausted && config.outputRestartPolicy === 'per-response/v2')
|
|
569
|
+
return { ...base,
|
|
570
|
+
phase: 'paused', resumePhase: 'preparing_context', outcome: null, reason: 'output_budget_exhausted',
|
|
571
|
+
modelErrors: 0, retryNotBefore: 0, messages };
|
|
557
572
|
return { ...base, phase: exhausted ? 'finalizing' : 'preparing_context', outcome: exhausted ? 'failed' : null,
|
|
558
573
|
reason: exhausted ? `${result.kind}_retry_exhausted` : null,
|
|
559
574
|
providerErrors: provider ? attempts : base.providerErrors ?? snapshot.providerErrors,
|
|
560
|
-
modelErrors: provider ? snapshot.modelErrors : attempts, retryNotBefore: exhausted ? 0 : now + delay,
|
|
561
|
-
messages: provider ? snapshot.messages : [...snapshot.messages, { role: 'user', kind: responseContinuationPending(snapshot, config)
|
|
562
|
-
? 'response_continuation_feedback' : 'model_feedback',
|
|
563
|
-
content: result.kind === 'empty_response' ? 'The last response was empty. Continue the task or provide a complete answer.' : 'The last tool call was malformed and was not executed. Return complete valid tool arguments.' }] };
|
|
575
|
+
modelErrors: provider ? snapshot.modelErrors : attempts, retryNotBefore: exhausted ? 0 : now + delay, messages };
|
|
564
576
|
}
|
|
565
577
|
case 'policy_abort': return { ...base, phase: 'finalizing', outcome: 'blocked', reason: 'model_policy_abort' };
|
|
566
578
|
case 'user_abort': return { ...base, phase: 'finalizing', outcome: 'unverified', reason: 'model_user_abort' };
|
package/dist/model-failure.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Observational only: these facts never authorize retries or tool execution. */
|
|
2
|
-
export declare const MODEL_FAILURE_CODES: readonly ["host_binding", "request_invalid", "http_authentication", "http_permission", "http_client", "http_server", "http_rate_limit", "http_timeout", "protocol_invalid", "json_invalid", "envelope_invalid", "provider_error", "identity_conflict", "usage_invalid", "usage_conflict", "choice_invalid", "delta_invalid", "termination_conflict", "framing_invalid", "body_limit", "body_encoding", "transport_error", "stream_timeout", "stream_incomplete", "tool_payload_invalid", "reasoning_repetition"];
|
|
2
|
+
export declare const MODEL_FAILURE_CODES: readonly ["host_binding", "request_invalid", "http_authentication", "http_permission", "http_client", "http_server", "http_rate_limit", "http_timeout", "protocol_invalid", "json_invalid", "envelope_invalid", "provider_error", "identity_conflict", "usage_invalid", "usage_conflict", "choice_invalid", "delta_invalid", "termination_conflict", "framing_invalid", "body_limit", "stream_frame_limit", "stream_output_limit", "tool_argument_limit", "body_encoding", "transport_error", "stream_timeout", "stream_incomplete", "tool_payload_invalid", "reasoning_repetition"];
|
|
3
3
|
/** Closed provider identifiers only; arbitrary provider strings can contain credentials. */
|
|
4
4
|
export declare const MODEL_PROVIDER_ERROR_CODES: readonly ["rate_limit_error", "rate_limit_exceeded", "overloaded_error", "server_error", "api_error", "service_unavailable_error", "server_is_overloaded", "timeout_error", "MODEL_PROVIDER_RATE_LIMIT", "MODEL_PROVIDER_UNAVAILABLE", "invalid_request_error", "invalid_api_key", "authentication_error", "permission_error", "not_found_error", "request_too_large", "billing_error", "insufficient_quota", "MODEL_PROVIDER_AUTHENTICATION", "MODEL_PROVIDER_PERMISSION", "MODEL_PROVIDER_INVALID_REQUEST", "MODEL_PROVIDER_NOT_FOUND", "MODEL_PROVIDER_QUOTA_EXHAUSTED"];
|
|
5
5
|
export declare const MODEL_PROVIDER_ERROR_TYPES: readonly ["rate_limit_error", "rate_limit_exceeded", "overloaded_error", "server_error", "api_error", "service_unavailable_error", "server_is_overloaded", "timeout_error", "MODEL_PROVIDER_RATE_LIMIT", "MODEL_PROVIDER_UNAVAILABLE", "invalid_request_error", "invalid_api_key", "authentication_error", "permission_error", "not_found_error", "request_too_large", "billing_error", "insufficient_quota", "MODEL_PROVIDER_AUTHENTICATION", "MODEL_PROVIDER_PERMISSION", "MODEL_PROVIDER_INVALID_REQUEST", "MODEL_PROVIDER_NOT_FOUND", "MODEL_PROVIDER_QUOTA_EXHAUSTED", "TooManyRequestsError", "ServiceUnavailableError", "RequestTimeoutError", "UnauthorizedError", "ForbiddenError", "InternalServerError", "BadRequestError", "NotFoundError", "AuthenticationError", "PermissionDeniedError", "RateLimitError"];
|
package/dist/model-failure.mjs
CHANGED
|
@@ -5,6 +5,7 @@ export const MODEL_FAILURE_CODES = [
|
|
|
5
5
|
'http_server', 'http_rate_limit', 'http_timeout', 'protocol_invalid', 'json_invalid',
|
|
6
6
|
'envelope_invalid', 'provider_error', 'identity_conflict', 'usage_invalid', 'usage_conflict',
|
|
7
7
|
'choice_invalid', 'delta_invalid', 'termination_conflict', 'framing_invalid', 'body_limit',
|
|
8
|
+
'stream_frame_limit', 'stream_output_limit', 'tool_argument_limit',
|
|
8
9
|
'body_encoding', 'transport_error', 'stream_timeout', 'stream_incomplete', 'tool_payload_invalid', 'reasoning_repetition',
|
|
9
10
|
];
|
|
10
11
|
/** Closed provider identifiers only; arbitrary provider strings can contain credentials. */
|
package/dist/model-json.mjs
CHANGED
|
@@ -9,7 +9,7 @@ function decodeJson(text, plainObjects, maxDepth) {
|
|
|
9
9
|
// The strict structural decoder still owns duplicate keys, exact integers
|
|
10
10
|
// and depth. Scan text spans in the engine rather than visiting each code
|
|
11
11
|
// unit in JS: persisted code/log strings dominate long-session reads.
|
|
12
|
-
const
|
|
12
|
+
const stringSpecial = /["\\]/g;
|
|
13
13
|
const numberToken = /-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/y;
|
|
14
14
|
function space() {
|
|
15
15
|
while (position < text.length) {
|
|
@@ -20,12 +20,22 @@ function decodeJson(text, plainObjects, maxDepth) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
function string() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const start = position++;
|
|
24
|
+
for (;;) {
|
|
25
|
+
stringSpecial.lastIndex = position;
|
|
26
|
+
const next = stringSpecial.exec(text);
|
|
27
|
+
invariant(next, 'invalid_model_json');
|
|
28
|
+
position = next.index + 1;
|
|
29
|
+
if (next[0] === '"')
|
|
30
|
+
break;
|
|
31
|
+
position++;
|
|
32
|
+
// Skip adjacent escape pairs without the regex engine stacking one
|
|
33
|
+
// repetition per escape in long serialized code or tool arguments.
|
|
34
|
+
while (text.charCodeAt(position) === 92)
|
|
35
|
+
position += 2;
|
|
36
|
+
}
|
|
27
37
|
// Native decoding validates escapes and rejects raw control characters.
|
|
28
|
-
return JSON.parse(
|
|
38
|
+
return JSON.parse(text.slice(start, position));
|
|
29
39
|
}
|
|
30
40
|
function value(depth) {
|
|
31
41
|
invariant(depth <= maxDepth, 'model_json_nesting_exceeded');
|
package/package.json
CHANGED
package/src/machine.mts
CHANGED
|
@@ -295,6 +295,8 @@ export function validateModelResult(input: ModelResult): ModelResult {
|
|
|
295
295
|
invariant(!failure || ['provider_terminal_error', 'provider_retryable_error', 'policy_abort', 'malformed_tool_call'].includes(result.kind)
|
|
296
296
|
|| result.kind === 'output_limit' && result.outputBoundary === 'no-visible-output/v1'
|
|
297
297
|
&& failure.phase === 'stream' && failure.code === 'reasoning_repetition'
|
|
298
|
+
|| result.kind === 'output_limit' && failure.phase === 'stream'
|
|
299
|
+
&& ['stream_frame_limit', 'stream_output_limit'].includes(failure.code)
|
|
298
300
|
|| result.kind === 'context_overflow' && failure.httpStatus === 400
|
|
299
301
|
&& (failure.gateway?.code === 'context_length_exceeded' || failure.gateway?.type === 'context_length_exceeded'),
|
|
300
302
|
'model_failure_diagnostic_requires_failure');
|
|
@@ -471,7 +473,7 @@ export function reduceModel(snapshot: RunSnapshot, input: ModelResult, config: R
|
|
|
471
473
|
: result.text ? 'The last response hit its output limit. Return only the exact missing suffix of that response. '
|
|
472
474
|
+ (responseBoundaryRecovery(config) ? 'You may replay the final incomplete line verbatim before continuing; the Host joins this exact overlap. Do not replay any complete line. ' : '')
|
|
473
475
|
+ 'Incomplete tool calls were not executed.'
|
|
474
|
-
: 'The last response hit its output limit without visible content or a committed tool call. Continue
|
|
476
|
+
: 'The last response hit its output limit without visible content or a committed tool call. Continue from the last committed state in smaller steps; answer only if the task is complete.' }];
|
|
475
477
|
return { mode, messages };
|
|
476
478
|
};
|
|
477
479
|
const exhausted = (): Partial<RunSnapshot> => resumable
|
|
@@ -517,18 +519,27 @@ export function reduceModel(snapshot: RunSnapshot, input: ModelResult, config: R
|
|
|
517
519
|
case 'provider_retryable_error': {
|
|
518
520
|
const provider = result.kind === 'provider_retryable_error';
|
|
519
521
|
const attempts = (provider ? snapshot.providerErrors : snapshot.modelErrors) + 1;
|
|
520
|
-
const
|
|
522
|
+
const oversizedTool = result.kind === 'malformed_tool_call' && result.failureDiagnostic?.code === 'tool_argument_limit';
|
|
523
|
+
const limit = provider ? config.profile.maxProviderRetries
|
|
524
|
+
: oversizedTool ? Math.min(config.profile.maxRetries, 1) : config.profile.maxRetries;
|
|
525
|
+
const exhausted = attempts > limit;
|
|
521
526
|
const delay = retryDelay(result, attempts, config, random);
|
|
522
527
|
// An unavailable provider is not a task failure: pause with a fresh budget so the Host can resume later.
|
|
523
528
|
if (provider && exhausted && config.providerRecoveryPolicy === 'provider-recovery/v2') return { ...base, phase: 'paused',
|
|
524
529
|
resumePhase: 'preparing_context', outcome: null, reason: 'provider_unavailable', providerErrors: 0, retryNotBefore: 0 };
|
|
530
|
+
const messages: Message[] = provider ? snapshot.messages : [...snapshot.messages, { role: 'user', kind: responseContinuationPending(snapshot, config)
|
|
531
|
+
? 'response_continuation_feedback' : 'model_feedback',
|
|
532
|
+
content: oversizedTool
|
|
533
|
+
? 'The last tool batch exceeded the tool input size limit and was not executed. Continue the task with smaller tool calls, splitting large file changes into separate edits. Keep all earlier tool results.'
|
|
534
|
+
: result.kind === 'empty_response' ? 'The last response was empty. Continue the task or provide a complete answer.'
|
|
535
|
+
: 'The last tool call was malformed and was not executed. Return complete valid tool arguments.' }];
|
|
536
|
+
if (oversizedTool && exhausted && config.outputRestartPolicy === 'per-response/v2') return { ...base,
|
|
537
|
+
phase: 'paused', resumePhase: 'preparing_context', outcome: null, reason: 'output_budget_exhausted',
|
|
538
|
+
modelErrors: 0, retryNotBefore: 0, messages };
|
|
525
539
|
return { ...base, phase: exhausted ? 'finalizing' : 'preparing_context', outcome: exhausted ? 'failed' : null,
|
|
526
540
|
reason: exhausted ? `${result.kind}_retry_exhausted` : null,
|
|
527
541
|
providerErrors: provider ? attempts : base.providerErrors ?? snapshot.providerErrors,
|
|
528
|
-
modelErrors: provider ? snapshot.modelErrors : attempts, retryNotBefore: exhausted ? 0 : now + delay,
|
|
529
|
-
messages: provider ? snapshot.messages : [...snapshot.messages, { role: 'user', kind: responseContinuationPending(snapshot, config)
|
|
530
|
-
? 'response_continuation_feedback' : 'model_feedback',
|
|
531
|
-
content: result.kind === 'empty_response' ? 'The last response was empty. Continue the task or provide a complete answer.' : 'The last tool call was malformed and was not executed. Return complete valid tool arguments.' }] };
|
|
542
|
+
modelErrors: provider ? snapshot.modelErrors : attempts, retryNotBefore: exhausted ? 0 : now + delay, messages };
|
|
532
543
|
}
|
|
533
544
|
case 'policy_abort': return { ...base, phase: 'finalizing', outcome: 'blocked', reason: 'model_policy_abort' };
|
|
534
545
|
case 'user_abort': return { ...base, phase: 'finalizing', outcome: 'unverified', reason: 'model_user_abort' };
|
package/src/model-failure.mts
CHANGED
|
@@ -6,6 +6,7 @@ export const MODEL_FAILURE_CODES = [
|
|
|
6
6
|
'http_server', 'http_rate_limit', 'http_timeout', 'protocol_invalid', 'json_invalid',
|
|
7
7
|
'envelope_invalid', 'provider_error', 'identity_conflict', 'usage_invalid', 'usage_conflict',
|
|
8
8
|
'choice_invalid', 'delta_invalid', 'termination_conflict', 'framing_invalid', 'body_limit',
|
|
9
|
+
'stream_frame_limit', 'stream_output_limit', 'tool_argument_limit',
|
|
9
10
|
'body_encoding', 'transport_error', 'stream_timeout', 'stream_incomplete', 'tool_payload_invalid', 'reasoning_repetition',
|
|
10
11
|
] as const;
|
|
11
12
|
/** Closed provider identifiers only; arbitrary provider strings can contain credentials. */
|
package/src/model-json.mts
CHANGED
|
@@ -12,7 +12,7 @@ function decodeJson(text: string, plainObjects: boolean, maxDepth: number): Json
|
|
|
12
12
|
// The strict structural decoder still owns duplicate keys, exact integers
|
|
13
13
|
// and depth. Scan text spans in the engine rather than visiting each code
|
|
14
14
|
// unit in JS: persisted code/log strings dominate long-session reads.
|
|
15
|
-
const
|
|
15
|
+
const stringSpecial = /["\\]/g;
|
|
16
16
|
const numberToken = /-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/y;
|
|
17
17
|
function space(): void {
|
|
18
18
|
while (position < text.length) {
|
|
@@ -22,12 +22,20 @@ function decodeJson(text: string, plainObjects: boolean, maxDepth: number): Json
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
function string(): string {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const start = position++;
|
|
26
|
+
for (;;) {
|
|
27
|
+
stringSpecial.lastIndex = position;
|
|
28
|
+
const next = stringSpecial.exec(text);
|
|
29
|
+
invariant(next, 'invalid_model_json');
|
|
30
|
+
position = next.index + 1;
|
|
31
|
+
if (next[0] === '"') break;
|
|
32
|
+
position++;
|
|
33
|
+
// Skip adjacent escape pairs without the regex engine stacking one
|
|
34
|
+
// repetition per escape in long serialized code or tool arguments.
|
|
35
|
+
while (text.charCodeAt(position) === 92) position += 2;
|
|
36
|
+
}
|
|
29
37
|
// Native decoding validates escapes and rejects raw control characters.
|
|
30
|
-
return JSON.parse(
|
|
38
|
+
return JSON.parse(text.slice(start, position)) as string;
|
|
31
39
|
}
|
|
32
40
|
function value(depth: number): Json {
|
|
33
41
|
invariant(depth <= maxDepth, 'model_json_nesting_exceeded'); space();
|