@kingsoftcloud/agentkit-harness-core 0.0.15 → 0.0.17
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/background-contract.d.mts +3 -0
- package/dist/background-contract.mjs +14 -0
- package/dist/child-contract.d.mts +6 -1
- package/dist/configuration.mjs +1 -1
- package/dist/context-planning.mjs +4 -1
- package/dist/contracts.d.mts +3 -1
- package/dist/kernel.mjs +1 -0
- package/dist/model-stream.d.mts +1 -1
- package/dist/model-stream.mjs +15 -11
- package/dist/transitions.mjs +2 -1
- package/package.json +1 -1
- package/src/background-contract.mts +12 -0
- package/src/child-contract.mts +3 -1
- package/src/configuration.mts +1 -1
- package/src/context-planning.mts +4 -1
- package/src/contracts.mts +3 -1
- package/src/kernel.mts +1 -0
- package/src/model-stream.mts +11 -8
- package/src/transitions.mts +2 -1
|
@@ -9,6 +9,9 @@ export interface BackgroundCommandState {
|
|
|
9
9
|
ref: BackgroundCommandRef;
|
|
10
10
|
notified: boolean;
|
|
11
11
|
}
|
|
12
|
+
/** Bound a read view without retiring any durable command ownership. Prefer
|
|
13
|
+
* commands whose completion has not been accounted for, then recent history. */
|
|
14
|
+
export declare function projectBackgroundCommands(rows: readonly BackgroundCommandState[], limit: number, recentLimit?: number): BackgroundCommandState[];
|
|
12
15
|
export interface BackgroundCommandRequest extends Omit<PortContext, 'signal'> {
|
|
13
16
|
schemaVersion: typeof BACKGROUND_COMMAND_CONTRACT;
|
|
14
17
|
cursor: string;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { copy, invariant } from './values.mjs';
|
|
2
2
|
export const BACKGROUND_COMMAND_CONTRACT = 'agentkit.background-command-observation/v1';
|
|
3
|
+
/** Bound a read view without retiring any durable command ownership. Prefer
|
|
4
|
+
* commands whose completion has not been accounted for, then recent history. */
|
|
5
|
+
export function projectBackgroundCommands(rows, limit, recentLimit = limit) {
|
|
6
|
+
const outstanding = [], recent = [];
|
|
7
|
+
for (let index = rows.length - 1; index >= 0 && outstanding.length < limit; index--) {
|
|
8
|
+
if (rows[index].notified === true) {
|
|
9
|
+
if (recent.length < recentLimit)
|
|
10
|
+
recent.push(index);
|
|
11
|
+
}
|
|
12
|
+
else
|
|
13
|
+
outstanding.push(index);
|
|
14
|
+
}
|
|
15
|
+
return [...outstanding, ...recent.slice(0, limit - outstanding.length)].sort((a, b) => a - b).map(index => rows[index]);
|
|
16
|
+
}
|
|
3
17
|
function object(input) {
|
|
4
18
|
invariant(input !== null && typeof input === 'object' && !Array.isArray(input), 'invalid_background_command_object');
|
|
5
19
|
return copy(input);
|
|
@@ -99,7 +99,12 @@ export interface ChildLifecyclePort {
|
|
|
99
99
|
}): Promise<{
|
|
100
100
|
childRunIds: string[];
|
|
101
101
|
}>;
|
|
102
|
-
/** Host
|
|
102
|
+
/** Dispose Host ownership without canceling an idle, resumable parent or its children. */
|
|
103
|
+
closeRun?(request: {
|
|
104
|
+
scope: RunScope;
|
|
105
|
+
runId: string;
|
|
106
|
+
}): Promise<void>;
|
|
107
|
+
/** Release terminal or explicitly canceled work, canceling any live descendants. */
|
|
103
108
|
releaseRun?(request: {
|
|
104
109
|
scope: RunScope;
|
|
105
110
|
runId: string;
|
package/dist/configuration.mjs
CHANGED
|
@@ -194,7 +194,7 @@ export function configure(input) {
|
|
|
194
194
|
const policy = profile.providerCompatibilityPolicy;
|
|
195
195
|
invariant(policy !== null && typeof policy === 'object' && !Array.isArray(policy)
|
|
196
196
|
&& Object.keys(policy).every(key => ['contract', 'rule'].includes(key))
|
|
197
|
-
&& ['provider-compat/v1', 'provider-compat/v2', 'provider-compat/v3', 'provider-compat/v4'].includes(policy.contract)
|
|
197
|
+
&& ['provider-compat/v1', 'provider-compat/v2', 'provider-compat/v3', 'provider-compat/v4', 'provider-compat/v5'].includes(policy.contract)
|
|
198
198
|
&& ['auto', 'permissive', 'openai', 'strict-openai', 'cerebras', 'groq', 'deepseek',
|
|
199
199
|
'zai', 'kspmas-gateway', 'moonshot', 'mimo'].includes(policy.rule), 'invalid_provider_compatibility_policy');
|
|
200
200
|
}
|
|
@@ -12,6 +12,7 @@ import { summaryContinuityInstructions, validSummaryContinuity } from './summary
|
|
|
12
12
|
import { responseBoundaryRecovery, responseContinuationPairs } from './response-continuation.mjs';
|
|
13
13
|
import { verificationModelView } from './model-surface.mjs';
|
|
14
14
|
import { currentInstructionContribution } from './context-contributions.mjs';
|
|
15
|
+
import { projectBackgroundCommands } from './background-contract.mjs';
|
|
15
16
|
const emptyState = () => ({ history: null, compaction: null, compactions: 0,
|
|
16
17
|
compactionsWithoutProgress: 0, progressDigest: null, lastModelCall: 0 });
|
|
17
18
|
export const contextMessageRef = (message, index, digest) => `message:${index}:${digest(message)}`;
|
|
@@ -39,6 +40,7 @@ export function contextContinuity(snapshot, config, policies = new NativePolicyR
|
|
|
39
40
|
const scopedEvidence = config.modelSurface?.verificationProjection === 'readable-evidence/v1';
|
|
40
41
|
const canReadArtifacts = config.artifactPolicy === 'runtime-artifacts/v1' && config.tools.some(tool => tool.name === 'ArtifactRead'
|
|
41
42
|
&& (config.contract.allowedToolNames === null || config.contract.allowedToolNames.includes(tool.name)));
|
|
43
|
+
const commands = projectBackgroundCommands(snapshot.backgroundCommands, 32, 8);
|
|
42
44
|
return copy({ schemaVersion: scopedEvidence ? 'agentkit.native-context-continuity/v2' : 'agentkit.native-context-continuity/v1', authority: 'host_record', goal: snapshot.goal,
|
|
43
45
|
...(snapshot.todos ? { todos: snapshot.todos.items, todoRevision: snapshot.todos.revision } : {}),
|
|
44
46
|
...(snapshot.planMode ? { planMode: snapshot.planMode, planModeGuidance: policies.forRun(config).planning.planModeGuidance(snapshot, config) } : {}),
|
|
@@ -54,7 +56,8 @@ export function contextContinuity(snapshot, config, policies = new NativePolicyR
|
|
|
54
56
|
childBudgetReservations: snapshot.childBudgetReservations ?? [], childRunIds: snapshot.childRunIds ?? [],
|
|
55
57
|
childApproval: snapshot.childApproval ?? null,
|
|
56
58
|
children: snapshot.children.map(child => ({ runId: child.runId, state: child.state, notified: child.notified })),
|
|
57
|
-
backgroundCommands:
|
|
59
|
+
backgroundCommands: commands.map(command => ({ ...command.ref, notified: command.notified })),
|
|
60
|
+
...(commands.length < snapshot.backgroundCommands.length ? { omittedBackgroundCommands: snapshot.backgroundCommands.length - commands.length } : {}),
|
|
58
61
|
verification: scopedEvidence ? verificationModelView(snapshot.verification, canReadArtifacts ? snapshot.artifactRefs : []) : snapshot.verification,
|
|
59
62
|
hostBindingDigest: config.hostBindingDigest,
|
|
60
63
|
...(snapshot.executionBudgetObservation ? { executionBudget: snapshot.executionBudgetObservation } : {}),
|
package/dist/contracts.d.mts
CHANGED
|
@@ -182,7 +182,7 @@ export interface ModelProfile {
|
|
|
182
182
|
rule: 'auto' | 'permissive' | 'openai' | 'strict-openai' | 'cerebras' | 'groq' | 'deepseek' | 'zai' | 'kspmas-gateway' | 'moonshot' | 'mimo';
|
|
183
183
|
};
|
|
184
184
|
providerCompatibilityPolicy?: {
|
|
185
|
-
contract: 'provider-compat/v1' | 'provider-compat/v2' | 'provider-compat/v3' | 'provider-compat/v4';
|
|
185
|
+
contract: 'provider-compat/v1' | 'provider-compat/v2' | 'provider-compat/v3' | 'provider-compat/v4' | 'provider-compat/v5';
|
|
186
186
|
rule: NonNullable<ModelProfile['inlineReasoningPolicy']>['rule'];
|
|
187
187
|
};
|
|
188
188
|
streaming?: boolean;
|
|
@@ -1099,6 +1099,8 @@ export interface PortContext extends RunIdentity {
|
|
|
1099
1099
|
}
|
|
1100
1100
|
export interface ModelRequest extends PortContext {
|
|
1101
1101
|
purpose?: 'task' | 'compaction' | 'delivery_review';
|
|
1102
|
+
/** Task generation before the first tool dispatch in this Run, including provider retries. */
|
|
1103
|
+
beforeFirstTool?: true;
|
|
1102
1104
|
profile: ModelProfile;
|
|
1103
1105
|
messages: Message[];
|
|
1104
1106
|
tools: ToolDefinition[];
|
package/dist/kernel.mjs
CHANGED
|
@@ -1180,6 +1180,7 @@ export class NativeKernel {
|
|
|
1180
1180
|
const review = intent.payload.purpose === 'delivery_review';
|
|
1181
1181
|
const beforeCall = { ...snapshot, usage: { ...snapshot.usage, modelCalls: snapshot.usage.modelCalls - 1 } };
|
|
1182
1182
|
return { ...context, profile: copy(configuration.profile), ...(review ? { purpose: 'delivery_review' } : {}),
|
|
1183
|
+
...(!review && snapshot.usage.toolCalls === 0 ? { beforeFirstTool: true } : {}),
|
|
1183
1184
|
messages: review ? snapshot.preparedContext ? modelContextMessages(snapshot, this.digest) : this.policies.forRun(configuration).review.deliveryReviewMessages(snapshot)
|
|
1184
1185
|
: configuration.profile.operatorGuidancePolicy === 'journaled-system/v1' ? modelContextMessages(snapshot, this.digest)
|
|
1185
1186
|
: deliveryTaskMessages(beforeCall, configuration, browserTaskMessages(beforeCall, configuration, modelContextMessages(snapshot, this.digest))),
|
package/dist/model-stream.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModelStreamEvent, ModelStreamRecord } from './contracts.mjs';
|
|
2
|
-
/**
|
|
2
|
+
/** Publish live output and retain a bounded public prefix for history. Neither supplies execution authority. */
|
|
3
3
|
export declare function modelStreamCapture(maxBytes: number, now: () => number, publish: (event: ModelStreamEvent, record: ModelStreamRecord) => void): {
|
|
4
4
|
emit(value: ModelStreamEvent): void;
|
|
5
5
|
close(): {
|
package/dist/model-stream.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { canonical, copy } from './values.mjs';
|
|
2
|
-
/**
|
|
2
|
+
/** Publish live output and retain a bounded public prefix for history. Neither supplies execution authority. */
|
|
3
3
|
export function modelStreamCapture(maxBytes, now, publish) {
|
|
4
4
|
const records = [];
|
|
5
|
-
let bytes = 2, truncated = false, discarded = 0, closed = false;
|
|
5
|
+
let bytes = 2, lastTime = 0, truncated = false, discarded = 0, closed = false;
|
|
6
6
|
return {
|
|
7
7
|
emit(value) {
|
|
8
|
-
if (closed
|
|
8
|
+
if (closed)
|
|
9
9
|
return;
|
|
10
10
|
if (!value || !['text', 'thinking', 'tool_delta'].includes(value.kind) || typeof value.text !== 'string') {
|
|
11
11
|
discarded++;
|
|
@@ -27,15 +27,19 @@ export function modelStreamCapture(maxBytes, now, publish) {
|
|
|
27
27
|
...(typeof value.metadata?.name === 'string' ? { name: value.metadata.name } : {}) };
|
|
28
28
|
}
|
|
29
29
|
const clock = now();
|
|
30
|
-
|
|
31
|
-
const record = { time, event };
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
lastTime = Math.max(lastTime, Number.isSafeInteger(clock) && clock >= 0 ? clock : 0);
|
|
31
|
+
const record = { time: lastTime, event };
|
|
32
|
+
if (!truncated) {
|
|
33
|
+
const size = new TextEncoder().encode(canonical(record)).length + (records.length ? 1 : 0);
|
|
34
|
+
if (bytes + size > maxBytes)
|
|
35
|
+
truncated = true;
|
|
36
|
+
else {
|
|
37
|
+
bytes += size;
|
|
38
|
+
records.push(record);
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
if (maxBytes === 0)
|
|
42
|
+
return;
|
|
39
43
|
// Display observers cannot veto or mutate the model result or receipt.
|
|
40
44
|
try {
|
|
41
45
|
publish(copy(event), copy(record));
|
package/dist/transitions.mjs
CHANGED
|
@@ -154,7 +154,8 @@ export function reduceCommand(snapshot, command, pending = null, bindings = {})
|
|
|
154
154
|
? { reason: null, continuations: 0, outputRestarts: 0 } : {}),
|
|
155
155
|
...(bindings.configuration?.approvalOutcomePolicy === APPROVAL_OUTCOME_POLICY
|
|
156
156
|
&& ['approval_rejected', 'approval_cancelled', 'approval_unavailable'].includes(snapshot.reason ?? '') ? { reason: null } : {}),
|
|
157
|
-
...(['provider_unavailable', 'context_summary_unavailable', '
|
|
157
|
+
...(['provider_unavailable', 'context_summary_unavailable', 'context_source_unavailable', 'child_paused']
|
|
158
|
+
.includes(snapshot.reason ?? '') ? { reason: null } : {}) };
|
|
158
159
|
break;
|
|
159
160
|
case 'submit_interaction': {
|
|
160
161
|
const pending = snapshot.pendingInteraction;
|
package/package.json
CHANGED
|
@@ -4,6 +4,18 @@ import { copy, invariant } from './values.mjs';
|
|
|
4
4
|
export const BACKGROUND_COMMAND_CONTRACT = 'agentkit.background-command-observation/v1' as const;
|
|
5
5
|
export interface BackgroundCommandRef { taskId: string; sourceRunId: string; operationKey: string }
|
|
6
6
|
export interface BackgroundCommandState { ref: BackgroundCommandRef; notified: boolean }
|
|
7
|
+
/** Bound a read view without retiring any durable command ownership. Prefer
|
|
8
|
+
* commands whose completion has not been accounted for, then recent history. */
|
|
9
|
+
export function projectBackgroundCommands(rows: readonly BackgroundCommandState[], limit: number,
|
|
10
|
+
recentLimit = limit): BackgroundCommandState[] {
|
|
11
|
+
const outstanding: number[] = [], recent: number[] = [];
|
|
12
|
+
for (let index = rows.length - 1; index >= 0 && outstanding.length < limit; index--) {
|
|
13
|
+
if (rows[index]!.notified === true) {
|
|
14
|
+
if (recent.length < recentLimit) recent.push(index);
|
|
15
|
+
} else outstanding.push(index);
|
|
16
|
+
}
|
|
17
|
+
return [...outstanding, ...recent.slice(0, limit - outstanding.length)].sort((a, b) => a - b).map(index => rows[index]!);
|
|
18
|
+
}
|
|
7
19
|
export interface BackgroundCommandRequest extends Omit<PortContext, 'signal'> {
|
|
8
20
|
schemaVersion: typeof BACKGROUND_COMMAND_CONTRACT; cursor: string; refs: BackgroundCommandRef[];
|
|
9
21
|
}
|
package/src/child-contract.mts
CHANGED
|
@@ -61,7 +61,9 @@ export interface ChildLifecyclePort {
|
|
|
61
61
|
/** Read already sealed child facts after a lost parent claim. Never starts, approves or cancels execution. */
|
|
62
62
|
reconcile?(request: ChildLifecycleRequest): Promise<ChildLifecycleResult | null>;
|
|
63
63
|
readyChildren?(request: ChildReadyRequest & { signal: AbortSignal }): Promise<{ childRunIds: string[] }>;
|
|
64
|
-
/** Host
|
|
64
|
+
/** Dispose Host ownership without canceling an idle, resumable parent or its children. */
|
|
65
|
+
closeRun?(request: { scope: RunScope; runId: string }): Promise<void>;
|
|
66
|
+
/** Release terminal or explicitly canceled work, canceling any live descendants. */
|
|
65
67
|
releaseRun?(request: { scope: RunScope; runId: string }): Promise<void>;
|
|
66
68
|
interruptedReceipts?(request: { scope: RunScope; runId: string; parentOperationKey: string }): Promise<{
|
|
67
69
|
parentOperationKey: string; parentToolCallId: string; result: ToolResult;
|
package/src/configuration.mts
CHANGED
|
@@ -249,7 +249,7 @@ export function configure(input: ConfigurationInput): RunConfiguration {
|
|
|
249
249
|
const policy = profile.providerCompatibilityPolicy;
|
|
250
250
|
invariant(policy !== null && typeof policy === 'object' && !Array.isArray(policy)
|
|
251
251
|
&& Object.keys(policy).every(key => ['contract', 'rule'].includes(key))
|
|
252
|
-
&& ['provider-compat/v1', 'provider-compat/v2', 'provider-compat/v3', 'provider-compat/v4'].includes(policy.contract)
|
|
252
|
+
&& ['provider-compat/v1', 'provider-compat/v2', 'provider-compat/v3', 'provider-compat/v4', 'provider-compat/v5'].includes(policy.contract)
|
|
253
253
|
&& ['auto', 'permissive', 'openai', 'strict-openai', 'cerebras', 'groq', 'deepseek',
|
|
254
254
|
'zai', 'kspmas-gateway', 'moonshot', 'mimo'].includes(policy.rule), 'invalid_provider_compatibility_policy');
|
|
255
255
|
}
|
package/src/context-planning.mts
CHANGED
|
@@ -14,6 +14,7 @@ import { summaryContinuityInstructions, validSummaryContinuity } from './summary
|
|
|
14
14
|
import { responseBoundaryRecovery, responseContinuationPairs } from './response-continuation.mjs';
|
|
15
15
|
import { verificationModelView } from './model-surface.mjs';
|
|
16
16
|
import { currentInstructionContribution } from './context-contributions.mjs';
|
|
17
|
+
import { projectBackgroundCommands } from './background-contract.mjs';
|
|
17
18
|
|
|
18
19
|
export interface ContextCounters {
|
|
19
20
|
/** Clock observation for this journaled context effect; never recomputed during counting. */
|
|
@@ -46,6 +47,7 @@ export function contextContinuity(snapshot: RunSnapshot, config: RunConfiguratio
|
|
|
46
47
|
const scopedEvidence = config.modelSurface?.verificationProjection === 'readable-evidence/v1';
|
|
47
48
|
const canReadArtifacts = config.artifactPolicy === 'runtime-artifacts/v1' && config.tools.some(tool => tool.name === 'ArtifactRead'
|
|
48
49
|
&& (config.contract.allowedToolNames === null || config.contract.allowedToolNames.includes(tool.name)));
|
|
50
|
+
const commands = projectBackgroundCommands(snapshot.backgroundCommands, 32, 8);
|
|
49
51
|
return copy({ schemaVersion: scopedEvidence ? 'agentkit.native-context-continuity/v2' : 'agentkit.native-context-continuity/v1', authority: 'host_record', goal: snapshot.goal,
|
|
50
52
|
...(snapshot.todos ? { todos: snapshot.todos.items, todoRevision: snapshot.todos.revision } : {}),
|
|
51
53
|
...(snapshot.planMode ? { planMode: snapshot.planMode, planModeGuidance: policies.forRun(config).planning.planModeGuidance(snapshot, config) } : {}),
|
|
@@ -61,7 +63,8 @@ export function contextContinuity(snapshot: RunSnapshot, config: RunConfiguratio
|
|
|
61
63
|
childBudgetReservations: snapshot.childBudgetReservations ?? [], childRunIds: snapshot.childRunIds ?? [],
|
|
62
64
|
childApproval: snapshot.childApproval ?? null,
|
|
63
65
|
children: snapshot.children.map(child => ({ runId: child.runId, state: child.state, notified: child.notified })),
|
|
64
|
-
backgroundCommands:
|
|
66
|
+
backgroundCommands: commands.map(command => ({ ...command.ref, notified: command.notified })),
|
|
67
|
+
...(commands.length < snapshot.backgroundCommands.length ? { omittedBackgroundCommands: snapshot.backgroundCommands.length - commands.length } : {}),
|
|
65
68
|
verification: scopedEvidence ? verificationModelView(snapshot.verification,
|
|
66
69
|
canReadArtifacts ? snapshot.artifactRefs : []) : snapshot.verification,
|
|
67
70
|
hostBindingDigest: config.hostBindingDigest,
|
package/src/contracts.mts
CHANGED
|
@@ -105,7 +105,7 @@ export interface ModelProfile {
|
|
|
105
105
|
/** Absent on older Runs; projection policy is frozen at admission. */
|
|
106
106
|
inlineReasoningPolicy?: { contract: 'profiled-content/v1' | 'profiled-content/v2'; rule: 'auto' | 'permissive' | 'openai'
|
|
107
107
|
| 'strict-openai' | 'cerebras' | 'groq' | 'deepseek' | 'zai' | 'kspmas-gateway' | 'moonshot' | 'mimo' };
|
|
108
|
-
providerCompatibilityPolicy?: { contract: 'provider-compat/v1' | 'provider-compat/v2' | 'provider-compat/v3' | 'provider-compat/v4'; rule: NonNullable<ModelProfile['inlineReasoningPolicy']>['rule'] };
|
|
108
|
+
providerCompatibilityPolicy?: { contract: 'provider-compat/v1' | 'provider-compat/v2' | 'provider-compat/v3' | 'provider-compat/v4' | 'provider-compat/v5'; rule: NonNullable<ModelProfile['inlineReasoningPolicy']>['rule'] };
|
|
109
109
|
streaming?: boolean; outputTokenParameter?: 'max_tokens' | 'max_completion_tokens';
|
|
110
110
|
streamTimeoutPolicy?: 'idle/v1'; providerThinkingDisplay?: boolean;
|
|
111
111
|
/** Absent on historical Runs, whose OpenAI usage reports required equality. */
|
|
@@ -630,6 +630,8 @@ export interface PortContext extends RunIdentity {
|
|
|
630
630
|
}
|
|
631
631
|
export interface ModelRequest extends PortContext {
|
|
632
632
|
purpose?: 'task' | 'compaction' | 'delivery_review';
|
|
633
|
+
/** Task generation before the first tool dispatch in this Run, including provider retries. */
|
|
634
|
+
beforeFirstTool?: true;
|
|
633
635
|
profile: ModelProfile; messages: Message[]; tools: ToolDefinition[]; finalizationOnly: boolean;
|
|
634
636
|
toolChoice?: 'auto' | 'none' | 'required' | { type: 'function'; function: { name: string } };
|
|
635
637
|
maxInlineImageBytes: number;
|
package/src/kernel.mts
CHANGED
|
@@ -1035,6 +1035,7 @@ export class NativeKernel {
|
|
|
1035
1035
|
const review = intent.payload.purpose === 'delivery_review';
|
|
1036
1036
|
const beforeCall = { ...snapshot, usage: { ...snapshot.usage, modelCalls: snapshot.usage.modelCalls - 1 } };
|
|
1037
1037
|
return { ...context, profile: copy(configuration.profile), ...(review ? { purpose: 'delivery_review' as const } : {}),
|
|
1038
|
+
...(!review && snapshot.usage.toolCalls === 0 ? { beforeFirstTool: true as const } : {}),
|
|
1038
1039
|
messages: review ? snapshot.preparedContext ? modelContextMessages(snapshot, this.digest) : this.policies.forRun(configuration).review.deliveryReviewMessages(snapshot)
|
|
1039
1040
|
: configuration.profile.operatorGuidancePolicy === 'journaled-system/v1' ? modelContextMessages(snapshot, this.digest)
|
|
1040
1041
|
: deliveryTaskMessages(beforeCall, configuration, browserTaskMessages(beforeCall, configuration, modelContextMessages(snapshot, this.digest))),
|
package/src/model-stream.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { ModelStreamEvent, ModelStreamRecord } from './contracts.mjs';
|
|
2
2
|
import { canonical, copy } from './values.mjs';
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/** Publish live output and retain a bounded public prefix for history. Neither supplies execution authority. */
|
|
5
5
|
export function modelStreamCapture(maxBytes: number, now: () => number,
|
|
6
6
|
publish: (event: ModelStreamEvent, record: ModelStreamRecord) => void) {
|
|
7
7
|
const records: ModelStreamRecord[] = [];
|
|
8
|
-
let bytes = 2, truncated = false, discarded = 0, closed = false;
|
|
8
|
+
let bytes = 2, lastTime = 0, truncated = false, discarded = 0, closed = false;
|
|
9
9
|
return {
|
|
10
10
|
emit(value: ModelStreamEvent) {
|
|
11
|
-
if (closed
|
|
11
|
+
if (closed) return;
|
|
12
12
|
if (!value || !['text', 'thinking', 'tool_delta'].includes(value.kind) || typeof value.text !== 'string') {
|
|
13
13
|
discarded++; return;
|
|
14
14
|
}
|
|
@@ -24,11 +24,14 @@ export function modelStreamCapture(maxBytes: number, now: () => number,
|
|
|
24
24
|
...(typeof value.metadata?.name === 'string' ? { name: value.metadata.name } : {}) };
|
|
25
25
|
}
|
|
26
26
|
const clock = now();
|
|
27
|
-
|
|
28
|
-
const record = { time, event };
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
lastTime = Math.max(lastTime, Number.isSafeInteger(clock) && clock >= 0 ? clock : 0);
|
|
28
|
+
const record = { time: lastTime, event };
|
|
29
|
+
if (!truncated) {
|
|
30
|
+
const size = new TextEncoder().encode(canonical(record)).length + (records.length ? 1 : 0);
|
|
31
|
+
if (bytes + size > maxBytes) truncated = true;
|
|
32
|
+
else { bytes += size; records.push(record); }
|
|
33
|
+
}
|
|
34
|
+
if (maxBytes === 0) return;
|
|
32
35
|
// Display observers cannot veto or mutate the model result or receipt.
|
|
33
36
|
try { publish(copy(event), copy(record)); } catch { /* non-authoritative observer */ }
|
|
34
37
|
},
|
package/src/transitions.mts
CHANGED
|
@@ -149,7 +149,8 @@ export function reduceCommand(snapshot: RunSnapshot, command: RunCommand, pendin
|
|
|
149
149
|
? { reason: null, continuations: 0, outputRestarts: 0 } : {}),
|
|
150
150
|
...(bindings.configuration?.approvalOutcomePolicy === APPROVAL_OUTCOME_POLICY
|
|
151
151
|
&& ['approval_rejected', 'approval_cancelled', 'approval_unavailable'].includes(snapshot.reason ?? '') ? { reason: null } : {}),
|
|
152
|
-
...(['provider_unavailable', 'context_summary_unavailable', '
|
|
152
|
+
...(['provider_unavailable', 'context_summary_unavailable', 'context_source_unavailable', 'child_paused']
|
|
153
|
+
.includes(snapshot.reason ?? '') ? { reason: null } : {}) };
|
|
153
154
|
break;
|
|
154
155
|
case 'submit_interaction': {
|
|
155
156
|
const pending = snapshot.pendingInteraction;
|