@kingsoftcloud/agentkit-harness-core 0.0.16 → 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.
@@ -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
  }
@@ -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))),
@@ -1,5 +1,5 @@
1
1
  import type { ModelStreamEvent, ModelStreamRecord } from './contracts.mjs';
2
- /** A bounded, public display prefix. It never supplies execution or replay authority. */
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(): {
@@ -1,11 +1,11 @@
1
1
  import { canonical, copy } from './values.mjs';
2
- /** A bounded, public display prefix. It never supplies execution or replay authority. */
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 || truncated)
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
- const time = Math.max(records.at(-1)?.time ?? 0, Number.isSafeInteger(clock) && clock >= 0 ? clock : 0);
31
- const record = { time, event };
32
- const size = new TextEncoder().encode(canonical(record)).length + (records.length ? 1 : 0);
33
- if (bytes + size > maxBytes) {
34
- truncated = true;
35
- return;
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
- bytes += size;
38
- records.push(record);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingsoftcloud/agentkit-harness-core",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Host-independent Native Harness contracts, transitions and durable execution.",
@@ -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/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))),
@@ -1,14 +1,14 @@
1
1
  import type { ModelStreamEvent, ModelStreamRecord } from './contracts.mjs';
2
2
  import { canonical, copy } from './values.mjs';
3
3
 
4
- /** A bounded, public display prefix. It never supplies execution or replay authority. */
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 || truncated) return;
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
- const time = Math.max(records.at(-1)?.time ?? 0, Number.isSafeInteger(clock) && clock >= 0 ? clock : 0);
28
- const record = { time, event };
29
- const size = new TextEncoder().encode(canonical(record)).length + (records.length ? 1 : 0);
30
- if (bytes + size > maxBytes) { truncated = true; return; }
31
- bytes += size; records.push(record);
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
  },