newmark-agent 0.5.14 → 0.5.15

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.
Files changed (64) hide show
  1. package/dist/conversation-utility-host.bundle.cjs +3373 -1900
  2. package/dist/conversation-utility-host.js +1 -1
  3. package/dist/core/agent.d.ts +105 -14
  4. package/dist/core/agent.js +658 -104
  5. package/dist/core/agentKernel/agent.d.ts +1 -0
  6. package/dist/core/agentKernel/agent.js +9 -0
  7. package/dist/core/agentKernelDiagnostics.d.ts +4 -6
  8. package/dist/core/agentKernelDiagnostics.js +12 -9
  9. package/dist/core/agentKernelRunner.d.ts +5 -0
  10. package/dist/core/agentKernelRunner.js +236 -85
  11. package/dist/core/autoRouter.js +16 -3
  12. package/dist/core/conversationCommandState.d.ts +17 -0
  13. package/dist/core/conversationCommandState.js +140 -0
  14. package/dist/core/conversationKernel.d.ts +25 -4
  15. package/dist/core/conversationKernel.js +347 -83
  16. package/dist/core/conversationListEvent.d.ts +6 -0
  17. package/dist/core/conversationListEvent.js +14 -0
  18. package/dist/core/electronUtilityAgentClient.d.ts +4 -1
  19. package/dist/core/electronUtilityAgentClient.js +4 -4
  20. package/dist/core/electronUtilityRuntimePool.d.ts +8 -2
  21. package/dist/core/electronUtilityRuntimePool.js +11 -5
  22. package/dist/core/installUpdate.js +41 -29
  23. package/dist/core/providerUsageAccounting.d.ts +47 -0
  24. package/dist/core/providerUsageAccounting.js +71 -0
  25. package/dist/core/requestContextEstimate.d.ts +18 -0
  26. package/dist/core/requestContextEstimate.js +54 -0
  27. package/dist/core/subagent.d.ts +89 -5
  28. package/dist/core/subagent.js +264 -41
  29. package/dist/core/subagentCommunication.d.ts +43 -0
  30. package/dist/core/subagentCommunication.js +167 -0
  31. package/dist/core/types.d.ts +32 -1
  32. package/dist/core/utilityAgentProtocol.d.ts +4 -0
  33. package/dist/core/workEventCoalescer.js +4 -1
  34. package/dist/core/wslAgentClient.d.ts +18 -5
  35. package/dist/core/wslAgentClient.js +79 -27
  36. package/dist/core/wslAgentProtocol.d.ts +7 -0
  37. package/dist/core/wslAgentRuntimePool.d.ts +8 -2
  38. package/dist/core/wslAgentRuntimePool.js +19 -6
  39. package/dist/core/wslRuntimeProcessTree.d.ts +10 -0
  40. package/dist/core/wslRuntimeProcessTree.js +104 -0
  41. package/dist/llm/provider.d.ts +5 -12
  42. package/dist/llm/provider.js +148 -267
  43. package/dist/main.js +582 -356
  44. package/dist/preload.js +3 -3
  45. package/dist/providers/chat-completions.adapter.d.ts +2 -0
  46. package/dist/providers/chat-completions.adapter.js +84 -36
  47. package/dist/providers/provider-adapter.d.ts +2 -0
  48. package/dist/providers/provider-events.d.ts +23 -14
  49. package/dist/providers/provider-events.js +148 -43
  50. package/dist/providers/provider-headers.d.ts +7 -3
  51. package/dist/providers/provider-headers.js +109 -39
  52. package/dist/providers/provider-request-compat.d.ts +6 -0
  53. package/dist/providers/provider-request-compat.js +37 -0
  54. package/dist/providers/responses.adapter.d.ts +2 -0
  55. package/dist/providers/responses.adapter.js +192 -126
  56. package/dist/server.d.ts +9 -2
  57. package/dist/server.js +100 -24
  58. package/dist/tools/index.js +17 -1
  59. package/dist/ui/index.html +2374 -616
  60. package/dist/ui/lucide-sprite.svg +7 -0
  61. package/dist/ui/startup.html +6 -6
  62. package/dist/wsl-agent-host.bundle.cjs +3381 -1906
  63. package/dist/wsl-agent-host.js +9 -4
  64. package/package.json +23 -4
@@ -65,7 +65,7 @@ async function handle(request) {
65
65
  return { ...result, backend: 'utility', pid: process.pid };
66
66
  }
67
67
  if (request.method === 'snapshot')
68
- return kernel.snapshot(checkedTarget(request.params.target));
68
+ return kernel.snapshot(checkedTarget(request.params.target), request.params.options);
69
69
  if (request.method === 'rewind') {
70
70
  return kernel.rewind(checkedTarget(request.params.target), request.params.messageIndex);
71
71
  }
@@ -1,3 +1,5 @@
1
+ import { type Accounting, type AccountingRequest, type UsageInput } from './providerUsageAccounting';
2
+ import { type RequestContextEstimate } from './requestContextEstimate';
1
3
  import { ConfigManager, ModelEvaluation, ProviderProtocol } from './config';
2
4
  import { LLMProvider } from '../llm/provider';
3
5
  import { ToolExecutor } from '../tools/index';
@@ -104,6 +106,7 @@ export interface FlowSuspensionRecord {
104
106
  result: string;
105
107
  }>;
106
108
  previousMode: AgentMode;
109
+ queueWasPaused?: boolean;
107
110
  reason: 'question' | 'interrupted';
108
111
  message?: string;
109
112
  options?: Array<{
@@ -127,6 +130,38 @@ export interface FlowSuspensionRecord {
127
130
  };
128
131
  updatedAt: string;
129
132
  }
133
+ interface ProviderUsageCounters {
134
+ input: number;
135
+ output: number;
136
+ cacheRead: number;
137
+ cacheWrite: number;
138
+ }
139
+ /** Caller-owned, single-Build reuse; never retained on Agent or shared globally. */
140
+ export interface BuildProviderCache {
141
+ key?: string;
142
+ provider?: LLMProvider;
143
+ }
144
+ export interface PeerRequestCache {
145
+ version: 1;
146
+ identity: string;
147
+ taskFocus: string;
148
+ initialTools: string[];
149
+ provisionedTools: string[];
150
+ }
151
+ interface ConversationProviderUsage {
152
+ version: 1;
153
+ totals: ProviderUsageCounters;
154
+ last: ProviderUsageCounters;
155
+ accounting?: Accounting;
156
+ requestContext?: RequestContextEstimate | null;
157
+ }
158
+ export interface ConversationUsageRequest {
159
+ id: string;
160
+ conversationId: string;
161
+ workspace: WorkspaceInfo | null;
162
+ stateKey: string | null;
163
+ accounting: AccountingRequest;
164
+ }
130
165
  export interface StoredGoalState {
131
166
  objective: string;
132
167
  changes: Array<{
@@ -268,6 +303,9 @@ export interface ConversationContinuation {
268
303
  }>;
269
304
  attachments?: ConversationImageAttachment[];
270
305
  hiddenUserInput?: boolean;
306
+ visibleUserInput?: string;
307
+ visibleMode?: string;
308
+ goalObjective?: string;
271
309
  createdAt: string;
272
310
  }
273
311
  export declare class Agent {
@@ -326,6 +364,8 @@ export declare class Agent {
326
364
  cacheRead: number;
327
365
  cacheWrite: number;
328
366
  };
367
+ private providerUsageAccounting;
368
+ private lastRequestContext;
329
369
  private compressionCache;
330
370
  private pendingHistoryRemovals;
331
371
  private branchMailbox;
@@ -365,15 +405,23 @@ export declare class Agent {
365
405
  private activeAgentKernelRuntime;
366
406
  private modelSwitchCompressionPromise;
367
407
  private activePeerAgents;
408
+ private peerProviderCaches;
368
409
  private awaitingAgentKernelRuntime;
369
410
  private pendingAgentKernelQueue;
370
411
  private linkedPlanAccess;
371
412
  private subagentContextPersist?;
413
+ private subagentPersistedHistory;
414
+ private subagentPersistedCompression;
372
415
  private agentKernelUserMessageStartSubscribers;
373
416
  private rootInboxWakeSubscribers;
417
+ private readonly directRootInboxQueuedIds;
418
+ private directRootWakePending;
419
+ private rootInboxRetiredSubscribers;
374
420
  private activeWorkRunId;
375
421
  private loadedWorkspaceConversationKey;
376
422
  private managedWorkRunIds;
423
+ /** Public deltas since the last completed response, retained only until its boundary. */
424
+ private pendingPublicWorkText;
377
425
  private finalizingWorkRunId;
378
426
  private agentRunService;
379
427
  private agentRunByWorkRunId;
@@ -399,6 +447,7 @@ export declare class Agent {
399
447
  private modelValidationPromise;
400
448
  private modelValidationProgress;
401
449
  private readonly rootInboxListener;
450
+ private boundSubagentManagerKey;
402
451
  readonly agentOnly: boolean;
403
452
  readonly runtimeActorId: string;
404
453
  readonly runtimeLifecycleRole: RuntimeLifecycleRole;
@@ -421,6 +470,8 @@ export declare class Agent {
421
470
  get toolchain(): ToolchainCore | null;
422
471
  constructor(rootPath: string, options?: AgentRuntimeOptions);
423
472
  setMode(m: AgentMode): void;
473
+ /** Selecting the composer mode does not start a Goal or reset a running Flow. */
474
+ selectConversationMode(mode: AgentMode): void;
424
475
  private currentConversationFlowSelection;
425
476
  private restoreConversationFlowSelection;
426
477
  setConversationFlow(name: string): ConversationFlowSelection;
@@ -567,6 +618,7 @@ export declare class Agent {
567
618
  setConversationWorkRunExpanded(runId: string, expanded: boolean): boolean;
568
619
  finishConversationWorkRun(runId: string, status: Exclude<ConversationWorkRunStatus, 'running'>, endedAt?: string, errorMessage?: string): boolean;
569
620
  private ensureCompletedWorkRunFinalResult;
621
+ private persistInterruptedPublicWorkText;
570
622
  emitWorkEvent(input: Omit<AgentWorkEvent, 'id' | 'conversationId' | 'mode' | 'model' | 'timestamp'> & Partial<Pick<AgentWorkEvent, 'conversationId' | 'mode' | 'model' | 'timestamp'>>): AgentWorkEvent;
571
623
  appendWorkflowMessage(content: string, toolName?: string, toolArgs?: string, persist?: boolean): void;
572
624
  recordToolResult(toolName: string, _result: string): void;
@@ -579,9 +631,14 @@ export declare class Agent {
579
631
  message: unknown;
580
632
  queueMode: 'steer' | 'followUp';
581
633
  }>;
634
+ removeQueuedMessages?(predicate: (message: unknown, queueMode: 'steer' | 'followUp') => boolean): number;
582
635
  } | null): void;
583
636
  subscribeAgentKernelUserMessageStart(fn: (content: string, clientMessageId?: string) => void): () => void;
584
- subscribeRootInboxWake(fn: (message: string) => boolean | void): () => void;
637
+ subscribeRootInboxWake(fn: (message: string, options?: {
638
+ wakeup: boolean;
639
+ }) => boolean | void, retired?: (ids: string[]) => void): () => void;
640
+ /** Called only after receipt-bearing tool history has been saved, or on cold replay. */
641
+ acknowledgeSubagentSettlementReceipts(): string[];
585
642
  notifyAgentKernelUserMessageStart(content: string, clientMessageId?: string): void;
586
643
  queueActiveKernelMessage(content: string, queueMode: 'steer' | 'followUp', clientMessageId?: string, runId?: string, images?: Array<{
587
644
  dataUrl: string;
@@ -624,9 +681,9 @@ export declare class Agent {
624
681
  private writeStoredConversationState;
625
682
  private scheduleStoredConversationState;
626
683
  flushWorkspaceConversationState(): void;
627
- getStoredFlowSuspension(conversationId?: string): FlowSuspensionRecord | null;
628
- saveStoredFlowSuspension(suspension: FlowSuspensionRecord | null, conversationId?: string): void;
629
- clearStoredFlowSuspension(conversationId?: string): void;
684
+ getStoredFlowSuspension(conversationId?: string, ws?: WorkspaceInfo | null): FlowSuspensionRecord | null;
685
+ saveStoredFlowSuspension(suspension: FlowSuspensionRecord | null, conversationId?: string, ws?: WorkspaceInfo | null): void;
686
+ clearStoredFlowSuspension(conversationId?: string, ws?: WorkspaceInfo | null): void;
630
687
  getStoredConversationDraft(conversationId?: string): string | undefined;
631
688
  saveStoredConversationDraft(draft: string | null, conversationId?: string): void;
632
689
  private writeStoredConversationStateNow;
@@ -671,9 +728,14 @@ export declare class Agent {
671
728
  private normalizeLinkedPlan;
672
729
  private subagentManagerKey;
673
730
  private bindConversationSubagents;
731
+ /** Release an idle facade; shared peer state remains available to its next owner. */
732
+ releaseConversationRuntimeBindings(): void;
733
+ private assertPeerOwnerCanSwitch;
674
734
  private persistSubagentState;
675
735
  private deliverActivePeerMailbox;
676
736
  private deliverRootInboxMessage;
737
+ /** A normal activation consumes queued mail without changing its static request prefix. */
738
+ flushDirectRootInbox(): void;
677
739
  private deliverPeerSettlement;
678
740
  private recordsForState;
679
741
  private conversationContentSignature;
@@ -683,7 +745,10 @@ export declare class Agent {
683
745
  workspace?: WorkspaceInfo | null;
684
746
  }): ConversationSnapshot;
685
747
  inspectConversationBranch(conversationId: string, branchId: string, branchGroupId?: string): ConversationSnapshot;
686
- ensureConversationSnapshot(conversationId?: string): ConversationSnapshot;
748
+ ensureConversationSnapshot(conversationId?: string, options?: {
749
+ window?: number;
750
+ before?: number;
751
+ }): ConversationSnapshot;
687
752
  rewindConversation(conversationId: string, messageIndex: number): ConversationSnapshot;
688
753
  branchConversation(conversationId: string, messageIndex: number, editedText: string, locator?: ConversationBranchLocator): ConversationSnapshot;
689
754
  setBranchCommunication(enabled: boolean): boolean;
@@ -721,6 +786,8 @@ export declare class Agent {
721
786
  * tool schema. An empty result keeps the formal response hard-blocked.
722
787
  */
723
788
  private deriveConversationTitleFromProvider;
789
+ private conversationTitleFailureCause;
790
+ private waitForConversationTitleRetry;
724
791
  /** Legacy completion hook retained as a no-op; naming is pre-response only. */
725
792
  private maybeAutoRenameConversationFromRun;
726
793
  private startFirstInputConversationTitle;
@@ -760,6 +827,7 @@ export declare class Agent {
760
827
  setInputMode(mode: string): InputMode;
761
828
  private defaultInputMode;
762
829
  abortActiveKernelRun(reason?: string): boolean;
830
+ hasRunningSubagents(): boolean;
763
831
  activeProcessSignal(): AbortSignal | undefined;
764
832
  recordWorkRunPrimaryPrompt(content: string): void;
765
833
  conversationBuildHistory(limit?: number): Array<{
@@ -854,7 +922,7 @@ export declare class Agent {
854
922
  handleContextHistoryManage(args: string): NewmarkToolResult;
855
923
  recordContextCompressionStep(): void;
856
924
  compressionContinuationPrompt(): string;
857
- mirrorConversationStateFrom(id: string, source: Pick<Agent, 'chatMessages' | 'history' | 'conversationPlan'> & Partial<Pick<Agent, 'linkedPlan' | 'subagents' | 'workRuns' | 'continuations' | 'getConversationTitleGateState'>> & {
925
+ mirrorConversationStateFrom(id: string, source: Pick<Agent, 'chatMessages' | 'history' | 'conversationPlan'> & Partial<Pick<Agent, 'linkedPlan' | 'subagents' | 'workRuns' | 'continuations' | 'getConversationTitleGateState' | 'providerUsageTotals' | 'lastProviderUsage' | 'conversationProviderUsage'>> & {
858
926
  modelSelection?: ConversationModelSelection;
859
927
  inputMode?: InputMode;
860
928
  mode?: AgentMode;
@@ -892,12 +960,15 @@ export declare class Agent {
892
960
  modelLabel(): string;
893
961
  estimateContextTokens(messages?: Array<Record<string, unknown>>): number;
894
962
  private estimateContextTokenComponents;
895
- recordProviderUsage(input: {
896
- input: number;
897
- output: number;
898
- cacheRead: number;
899
- cacheWrite: number;
900
- }): void;
963
+ private normalizeProviderUsageCounters;
964
+ conversationProviderUsage(): ConversationProviderUsage;
965
+ private normalizedConversationUsage;
966
+ private restoreProviderUsage;
967
+ private mutateRequestUsage;
968
+ beginProviderUsageRequest(): ConversationUsageRequest;
969
+ recordRequestContext(request: ConversationUsageRequest, messages: Array<Record<string, unknown>>, system: string, tools: unknown[], model: string): void;
970
+ recordProviderUsage(input: UsageInput, request?: ConversationUsageRequest): void;
971
+ private chatWithConversationUsage;
901
972
  contextWindow(modelName?: string): {
902
973
  estimatedTokens: number;
903
974
  maxTokens: number;
@@ -919,7 +990,20 @@ export declare class Agent {
919
990
  providerOutputTokens?: number;
920
991
  providerCacheReadTokens?: number;
921
992
  providerCacheWriteTokens?: number;
922
- providerCacheReadRatio?: number;
993
+ providerCacheReadRatio?: number | null;
994
+ providerKnownCacheReadRatio?: number | null;
995
+ providerCacheEligibleInputTokens?: number;
996
+ providerUsageRequests?: number;
997
+ providerUsageInputReportedRequests?: number;
998
+ providerUsageOutputReportedRequests?: number;
999
+ providerUsageCacheReportedRequests?: number;
1000
+ providerUsageHasLegacyTotals?: boolean;
1001
+ providerLastInputTokens?: number | null;
1002
+ requestContext?: RequestContextEstimate | null;
1003
+ contextEstimateSource?: 'active_request' | 'history';
1004
+ contextEstimateHasImages?: boolean;
1005
+ systemPromptTokens?: number;
1006
+ toolSchemaTokens?: number;
923
1007
  };
924
1008
  private resolveWindowModel;
925
1009
  private contextMaxTokens;
@@ -1029,7 +1113,8 @@ export declare class Agent {
1029
1113
  * has been exhausted; the original image is never sent again.
1030
1114
  */
1031
1115
  finalVisualFallback(errorText: string, signal?: AbortSignal): Promise<string | null>;
1032
- engineModel(): LLMProvider | null;
1116
+ engineModel(cache?: BuildProviderCache): LLMProvider | null;
1117
+ private modelProvider;
1033
1118
  /**
1034
1119
  * dev-0.4.3 模型原生思考强度档位映射表(模型名 → thinking_tier_map)。
1035
1120
  * 未配置映射的模型返回 undefined,provider 侧维持默认透传(不变动映射)。
@@ -1145,6 +1230,12 @@ export declare class Agent {
1145
1230
  * empty here; linked-plan content is tool-retrieved on demand.
1146
1231
  */
1147
1232
  assembleContextV2(toolSurfaceNotice: string): AssembledContext;
1233
+ private subagentSettlementReceipt;
1234
+ /** Peer jobs share a durable request prefix; credentials only enter its hash. */
1235
+ peerRequestCacheIdentity(systemPrompt: string, catalog: unknown[]): string | undefined;
1236
+ readPeerRequestCache(identity: string | undefined): PeerRequestCache | undefined;
1237
+ persistPeerRequestCache(cache: PeerRequestCache): void;
1238
+ checkpointPeerInput(): void;
1148
1239
  cachedToolDefinitions(): unknown[];
1149
1240
  private buildFeatureDisclosurePrompt;
1150
1241
  private buildVisibleOutputContract;