@peer-agent/runtime-core 0.1.0-rc.35 → 0.1.0-rc.36

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.
@@ -40,6 +40,7 @@ export interface CompactionSummaryCascadeOptions<TMessage extends CompactionMess
40
40
  readonly summarizeStructurally: (messages: readonly TMessage[]) => string | null | undefined;
41
41
  readonly fallbackSummary?: string;
42
42
  }
43
+ export declare function isHumanUserMessage(message: Partial<Pick<CompactionMessage, 'role' | 'content' | '_compaction'>>): boolean;
43
44
  /**
44
45
  * Host-neutral form of Desktop's compaction split rules. System messages are kept
45
46
  * separately; automatic preflight preserves the newest human turn; and a split
@@ -126,7 +126,7 @@ function toolResultIds(message) {
126
126
  function hasToolResult(message) {
127
127
  return message.role === 'tool' || toolResultIds(message).length > 0;
128
128
  }
129
- function isHumanUserMessage(message) {
129
+ export function isHumanUserMessage(message) {
130
130
  if (message.role !== 'user' || message._compaction)
131
131
  return false;
132
132
  const blocks = contentBlocks(message);
@@ -1,3 +1,4 @@
1
+ import type { CanonicalToolMaterialObservation } from '@peer-agent/protocol';
1
2
  export type RuntimeCapabilityId = string;
2
3
  export type RuntimeProviderId = string;
3
4
  export type RuntimeRunId = string;
@@ -29,6 +30,8 @@ export interface RuntimeToolError {
29
30
  readonly details?: unknown;
30
31
  }
31
32
  export interface RuntimeToolResult {
33
+ /** Local canonical bytes; non-enumerable, never event/renderer/provider-message data. */
34
+ readonly materialObservation?: CanonicalToolMaterialObservation;
32
35
  readonly toolCallId: string;
33
36
  readonly capabilityId: RuntimeCapabilityId;
34
37
  readonly status: RuntimeToolStatus;
@@ -1,4 +1,4 @@
1
- import { formatResourceFeedbackContext } from '@peer-agent/protocol';
1
+ import { formatResourceFeedbackContext, projectResourceFeedbackTransport } from '@peer-agent/protocol';
2
2
  /**
3
3
  * Canonical persisted-conversation -> active provider history projection.
4
4
  *
@@ -128,12 +128,12 @@ function attachmentText(attachments) {
128
128
  return blocks.join('\n\n');
129
129
  }
130
130
  function userMessage(message) {
131
- const attachments = Array.isArray(message.attachments)
132
- ? message.attachments
133
- : [];
131
+ const material = projectResourceFeedbackTransport(message.resourceFeedback, message.attachments);
132
+ const attachments = material.attachments;
134
133
  const text = [
135
134
  typeof message.content === 'string' ? message.content : '',
136
- formatResourceFeedbackContext(message.resourceFeedback),
135
+ formatResourceFeedbackContext(material.invalid ? null : material.resourceFeedback),
136
+ ...(material.invalid ? ['[Resource feedback could not be restored. Retained attachments are unverified user material.]'] : []),
137
137
  attachmentText(attachments),
138
138
  ].filter((value) => value.trim()).join('\n\n');
139
139
  const parts = [];
package/dist/evidence.js CHANGED
@@ -30,6 +30,7 @@ export function collectToolEvidenceRefs(options = {}) {
30
30
  const execution = asEvidenceObject(options.execution);
31
31
  const result = asEvidenceObject(execution?.result);
32
32
  const evidence = asEvidenceObject(result?.evidence);
33
+ addEvidenceRefStrings(refs, evidence?.refs);
33
34
  addEvidenceRefStrings(refs, evidence?.artifactRefs);
34
35
  const outputPreview = asEvidenceObject(result?.outputPreview);
35
36
  addEvidenceRefStrings(refs, outputPreview?.artifactRef);
@@ -35,4 +35,6 @@ export declare function extractRecoverableClues(text: unknown, { limit }?: {
35
35
  * 对「最近 keepRecentCount 条非 system 消息之外」的历史消息做证据引用化/预览化。
36
36
  * system 与 `_compaction` handoff 不参与;已是 local_*_ref 的结果保留骨架不重复截断。
37
37
  */
38
- export declare function microcompactMessagesForContext<TMessage extends MicrocompactMessage>(messages: readonly TMessage[], options?: Partial<typeof MICROCOMPACTION_CONFIG>): MicrocompactResult<TMessage>;
38
+ export declare function microcompactMessagesForContext<TMessage extends MicrocompactMessage>(messages: readonly TMessage[], options?: Partial<typeof MICROCOMPACTION_CONFIG> & {
39
+ preserveLatestUserTurn?: boolean;
40
+ }): MicrocompactResult<TMessage>;
@@ -6,6 +6,7 @@
6
6
  // 保留骨架与检索路径;无结构的长文本抽取可回捞线索(artifact/path/retrieval)后再预览化。
7
7
  //
8
8
  // 原则(17 号文档):It moves evidence out of prompt and keeps the route back.
9
+ import { isHumanUserMessage } from "./context-compaction.js";
9
10
  export const MICROCOMPACTION_CONFIG = Object.freeze({
10
11
  keepRecentCount: 8,
11
12
  triggerChars: 6_000,
@@ -309,6 +310,7 @@ function microcompactMessageContent(content, config) {
309
310
  */
310
311
  export function microcompactMessagesForContext(messages, options = {}) {
311
312
  const config = { ...MICROCOMPACTION_CONFIG, ...options };
313
+ let protectLatestUser = options.preserveLatestUserTurn === true;
312
314
  let recentNonSystemSeen = 0;
313
315
  const compactableIndexes = new Set();
314
316
  for (let index = messages.length - 1; index >= 0; index--) {
@@ -316,6 +318,10 @@ export function microcompactMessagesForContext(messages, options = {}) {
316
318
  if (message?.role === 'system' || message?._compaction)
317
319
  continue;
318
320
  recentNonSystemSeen++;
321
+ if (protectLatestUser && message && isHumanUserMessage(message)) {
322
+ protectLatestUser = false;
323
+ continue;
324
+ }
319
325
  if (recentNonSystemSeen > config.keepRecentCount) {
320
326
  compactableIndexes.add(index);
321
327
  }
@@ -1,4 +1,4 @@
1
- import { normalizeResourceFeedbackList, emptyInputDraft, projectInputWasReceived } from '@peer-agent/protocol';
1
+ import { encodeResourceFeedbackTransport, normalizeResourceFeedbackList, emptyInputDraft, projectInputWasReceived } from '@peer-agent/protocol';
2
2
  /** Presentation continuity only; ports own storage and the existing governed input queue. */
3
3
  export function createProjectInputRecovery({ workspaceId, surface, port, createId, now = () => new Date().toISOString(), receiptTimeoutMs = 30_000 }) {
4
4
  const address = { workspaceId, surface };
@@ -144,7 +144,10 @@ export function createProjectInputRecovery({ workspaceId, surface, port, createI
144
144
  const text = (options.text ?? draft.text).trim(), attachments = useDraft ? draft.attachments : [];
145
145
  if (useDraft && options.text !== undefined && text !== draft.text.trim())
146
146
  return { ok: false, code: 'INPUT_CHANGED' };
147
- if (!text && !attachments.length)
147
+ const resourceFeedback = useDraft ? normalizeResourceFeedbackList(draft.resourceFeedback) : [];
148
+ if (!resourceFeedback)
149
+ return { ok: false, code: 'INVALID_RESOURCE_FEEDBACK' };
150
+ if (!text && !attachments.length && !resourceFeedback.some(row => row.resource.kind === 'interactive'))
148
151
  return { ok: false, code: 'INVALID_INPUT' };
149
152
  if (!useDraft && options.answerTo) {
150
153
  const existing = view.pending.find(item => item.answerTo === options.answerTo);
@@ -153,11 +156,14 @@ export function createProjectInputRecovery({ workspaceId, surface, port, createI
153
156
  }
154
157
  if (view.pending.length >= 32)
155
158
  return { ok: false, code: 'DRAFT_LIMIT' };
156
- const resourceFeedback = useDraft ? normalizeResourceFeedbackList(draft.resourceFeedback) : [];
157
- if (!resourceFeedback)
158
- return { ok: false, code: 'INVALID_RESOURCE_FEEDBACK' };
159
159
  if (resourceFeedback.some(item => item.recipient.workspaceId !== workspaceId))
160
160
  return { ok: false, code: 'RESOURCE_FEEDBACK_RECIPIENT_CHANGED' };
161
+ try {
162
+ encodeResourceFeedbackTransport(resourceFeedback, attachments);
163
+ }
164
+ catch (error) {
165
+ return { ok: false, code: error.code ?? 'INVALID_RESOURCE_FEEDBACK' };
166
+ }
161
167
  const input = { inputId: createId(), text, attachments, ...(resourceFeedback.length ? { resourceFeedback } : {}), createdAt: now(), quoteRefs: options.quoteRefs ?? [],
162
168
  ...(options.answerTo ? { answerTo: options.answerTo } : {}) };
163
169
  changed++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/runtime-core",
3
- "version": "0.1.0-rc.35",
3
+ "version": "0.1.0-rc.36",
4
4
  "description": "Host-neutral capability, permission, projection, and Evidence primitives for Peer Agent runtimes.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "LICENSE"
39
39
  ],
40
40
  "dependencies": {
41
- "@peer-agent/protocol": "0.1.0-rc.35"
41
+ "@peer-agent/protocol": "0.1.0-rc.36"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "^5.9.3"