@pellux/goodvibes-sdk 1.0.0 → 1.1.0
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/contracts/artifacts/operator-contract.json +1320 -10
- package/dist/events/communication.d.ts +1 -1
- package/dist/platform/agents/orchestrator-runner.d.ts +5 -5
- package/dist/platform/agents/orchestrator-runner.js +6 -6
- package/dist/platform/agents/orchestrator.d.ts +4 -4
- package/dist/platform/agents/orchestrator.js +2 -2
- package/dist/platform/agents/wrfc-controller.d.ts +1 -1
- package/dist/platform/agents/wrfc-controller.js +3 -3
- package/dist/platform/calendar/index.d.ts +2 -2
- package/dist/platform/calendar/index.js +3 -3
- package/dist/platform/calendar/oauth-providers.d.ts +1 -1
- package/dist/platform/calendar/oauth-providers.js +1 -1
- package/dist/platform/calendar/oauth-types.d.ts +1 -1
- package/dist/platform/calendar/oauth-types.js +1 -1
- package/dist/platform/companion/companion-chat-branching.d.ts +66 -0
- package/dist/platform/companion/companion-chat-branching.d.ts.map +1 -0
- package/dist/platform/companion/companion-chat-branching.js +142 -0
- package/dist/platform/companion/companion-chat-broker-bridge.d.ts +1 -1
- package/dist/platform/companion/companion-chat-broker-bridge.d.ts.map +1 -1
- package/dist/platform/companion/companion-chat-broker-sync.d.ts +2 -2
- package/dist/platform/companion/companion-chat-broker-sync.d.ts.map +1 -1
- package/dist/platform/companion/companion-chat-broker-sync.js +1 -1
- package/dist/platform/companion/companion-chat-manager.d.ts +26 -5
- package/dist/platform/companion/companion-chat-manager.d.ts.map +1 -1
- package/dist/platform/companion/companion-chat-manager.js +67 -81
- package/dist/platform/companion/companion-chat-routes.d.ts.map +1 -1
- package/dist/platform/companion/companion-chat-routes.js +77 -1
- package/dist/platform/companion/companion-chat-turn-execution.d.ts +61 -0
- package/dist/platform/companion/companion-chat-turn-execution.d.ts.map +1 -0
- package/dist/platform/companion/companion-chat-turn-execution.js +107 -0
- package/dist/platform/companion/companion-chat-types.d.ts +67 -0
- package/dist/platform/companion/companion-chat-types.d.ts.map +1 -1
- package/dist/platform/config/credential-status.d.ts +1 -1
- package/dist/platform/config/credential-status.js +1 -1
- package/dist/platform/config/index.d.ts +1 -1
- package/dist/platform/config/index.js +1 -1
- package/dist/platform/config/manager.d.ts +1 -1
- package/dist/platform/config/manager.js +1 -1
- package/dist/platform/config/migrations.d.ts +2 -2
- package/dist/platform/config/migrations.js +2 -2
- package/dist/platform/config/schema-domain-runtime.d.ts +8 -0
- package/dist/platform/config/schema-domain-runtime.d.ts.map +1 -1
- package/dist/platform/config/schema-domain-runtime.js +32 -0
- package/dist/platform/config/schema-types.d.ts +10 -2
- package/dist/platform/config/schema-types.d.ts.map +1 -1
- package/dist/platform/control-plane/gateway-scope-enforcement.js +2 -2
- package/dist/platform/control-plane/index.d.ts +2 -0
- package/dist/platform/control-plane/index.d.ts.map +1 -1
- package/dist/platform/control-plane/index.js +5 -1
- package/dist/platform/control-plane/invoke-input-validation.d.ts +1 -1
- package/dist/platform/control-plane/invoke-input-validation.js +1 -1
- package/dist/platform/control-plane/method-catalog-calendar.d.ts +2 -2
- package/dist/platform/control-plane/method-catalog-calendar.js +2 -2
- package/dist/platform/control-plane/method-catalog-channels.js +3 -3
- package/dist/platform/control-plane/method-catalog-control-automation.js +4 -4
- package/dist/platform/control-plane/method-catalog-control-companion.d.ts +1 -1
- package/dist/platform/control-plane/method-catalog-control-companion.d.ts.map +1 -1
- package/dist/platform/control-plane/method-catalog-control-companion.js +43 -0
- package/dist/platform/control-plane/method-catalog-control-core.js +3 -3
- package/dist/platform/control-plane/method-catalog-email.d.ts +1 -1
- package/dist/platform/control-plane/method-catalog-email.js +1 -1
- package/dist/platform/control-plane/method-catalog-fleet.d.ts +1 -1
- package/dist/platform/control-plane/method-catalog-push.d.ts +30 -0
- package/dist/platform/control-plane/method-catalog-push.d.ts.map +1 -0
- package/dist/platform/control-plane/method-catalog-push.js +80 -0
- package/dist/platform/control-plane/method-catalog-route-reconcile.d.ts +1 -1
- package/dist/platform/control-plane/method-catalog-runtime.d.ts.map +1 -1
- package/dist/platform/control-plane/method-catalog-runtime.js +83 -1
- package/dist/platform/control-plane/method-catalog.d.ts.map +1 -1
- package/dist/platform/control-plane/method-catalog.js +2 -0
- package/dist/platform/control-plane/operator-contract-schemas-fleet.js +1 -1
- package/dist/platform/control-plane/operator-contract-schemas-runtime.d.ts +8 -0
- package/dist/platform/control-plane/operator-contract-schemas-runtime.d.ts.map +1 -1
- package/dist/platform/control-plane/operator-contract-schemas-runtime.js +43 -0
- package/dist/platform/control-plane/routes/checkpoints.d.ts +1 -1
- package/dist/platform/control-plane/routes/fleet.d.ts +2 -2
- package/dist/platform/control-plane/routes/fleet.js +1 -1
- package/dist/platform/control-plane/routes/gateway-verb-error.d.ts +1 -1
- package/dist/platform/control-plane/routes/gateway-verb-error.js +1 -1
- package/dist/platform/control-plane/routes/index.js +1 -1
- package/dist/platform/control-plane/routes/invocation-params.d.ts +1 -1
- package/dist/platform/control-plane/routes/push.d.ts +26 -0
- package/dist/platform/control-plane/routes/push.d.ts.map +1 -0
- package/dist/platform/control-plane/routes/push.js +104 -0
- package/dist/platform/control-plane/routes/register-gateway-verb-groups.d.ts +31 -0
- package/dist/platform/control-plane/routes/register-gateway-verb-groups.d.ts.map +1 -0
- package/dist/platform/control-plane/routes/register-gateway-verb-groups.js +16 -0
- package/dist/platform/control-plane/routes/register-w3-s2.d.ts +2 -2
- package/dist/platform/control-plane/routes/session-search.d.ts +4 -4
- package/dist/platform/control-plane/session-broker.d.ts +1 -1
- package/dist/platform/control-plane/session-broker.js +1 -1
- package/dist/platform/control-plane/session-store-importer.d.ts +1 -1
- package/dist/platform/control-plane/session-store-importer.js +1 -1
- package/dist/platform/control-plane/session-types.d.ts +1 -1
- package/dist/platform/core/orchestrator-runtime.d.ts +4 -4
- package/dist/platform/core/orchestrator-tool-runtime.d.ts +1 -1
- package/dist/platform/core/orchestrator-turn-loop.d.ts +6 -6
- package/dist/platform/core/orchestrator-turn-loop.d.ts.map +1 -1
- package/dist/platform/core/orchestrator-turn-loop.js +23 -22
- package/dist/platform/core/orchestrator.d.ts +10 -10
- package/dist/platform/core/orchestrator.d.ts.map +1 -1
- package/dist/platform/core/orchestrator.js +8 -8
- package/dist/platform/daemon/boot.d.ts +6 -0
- package/dist/platform/daemon/boot.d.ts.map +1 -1
- package/dist/platform/daemon/boot.js +1 -0
- package/dist/platform/daemon/control-plane.js +2 -2
- package/dist/platform/daemon/facade.d.ts +4 -7
- package/dist/platform/daemon/facade.d.ts.map +1 -1
- package/dist/platform/daemon/facade.js +5 -7
- package/dist/platform/daemon/http/router-session-broker-adapter.d.ts +1 -1
- package/dist/platform/daemon/http/router.d.ts +1 -0
- package/dist/platform/daemon/http/router.d.ts.map +1 -1
- package/dist/platform/daemon/http/router.js +36 -19
- package/dist/platform/daemon/http/runtime-route-types.d.ts +1 -1
- package/dist/platform/daemon/http/runtime-route-types.d.ts.map +1 -1
- package/dist/platform/daemon/http/webui-serving.d.ts +68 -0
- package/dist/platform/daemon/http/webui-serving.d.ts.map +1 -0
- package/dist/platform/daemon/http/webui-serving.js +230 -0
- package/dist/platform/knowledge/knowledge-api.d.ts +1 -1
- package/dist/platform/orchestration/budget.d.ts +2 -2
- package/dist/platform/orchestration/cancellation.d.ts +2 -2
- package/dist/platform/orchestration/controller-compat.d.ts +2 -3
- package/dist/platform/orchestration/controller-compat.d.ts.map +1 -1
- package/dist/platform/orchestration/dirty-guard.js +1 -1
- package/dist/platform/orchestration/engine.d.ts.map +1 -1
- package/dist/platform/orchestration/engine.js +3 -4
- package/dist/platform/orchestration/persistence.js +2 -2
- package/dist/platform/orchestration/phase-runner.d.ts +4 -4
- package/dist/platform/orchestration/scheduler.d.ts +1 -1
- package/dist/platform/orchestration/types.d.ts +3 -3
- package/dist/platform/presentation/glyphs.d.ts +1 -1
- package/dist/platform/presentation/glyphs.js +1 -1
- package/dist/platform/presentation/index.d.ts +3 -3
- package/dist/platform/presentation/index.js +3 -3
- package/dist/platform/presentation/thinking-phrases.d.ts +1 -1
- package/dist/platform/presentation/thinking-phrases.js +1 -1
- package/dist/platform/presentation/waiting-wording.d.ts +1 -1
- package/dist/platform/presentation/waiting-wording.js +1 -1
- package/dist/platform/push/delivery.d.ts +48 -0
- package/dist/platform/push/delivery.d.ts.map +1 -0
- package/dist/platform/push/delivery.js +117 -0
- package/dist/platform/push/encryption.d.ts +41 -0
- package/dist/platform/push/encryption.d.ts.map +1 -0
- package/dist/platform/push/encryption.js +82 -0
- package/dist/platform/push/index.d.ts +17 -0
- package/dist/platform/push/index.d.ts.map +1 -0
- package/dist/platform/push/index.js +10 -0
- package/dist/platform/push/service.d.ts +75 -0
- package/dist/platform/push/service.d.ts.map +1 -0
- package/dist/platform/push/service.js +95 -0
- package/dist/platform/push/subscription-store.d.ts +50 -0
- package/dist/platform/push/subscription-store.d.ts.map +1 -0
- package/dist/platform/push/subscription-store.js +123 -0
- package/dist/platform/push/types.d.ts +68 -0
- package/dist/platform/push/types.d.ts.map +1 -0
- package/dist/platform/push/types.js +13 -0
- package/dist/platform/push/vapid.d.ts +54 -0
- package/dist/platform/push/vapid.d.ts.map +1 -0
- package/dist/platform/push/vapid.js +113 -0
- package/dist/platform/runtime/feature-flags/flags.js +3 -3
- package/dist/platform/runtime/fleet/adapters/agent.d.ts +2 -2
- package/dist/platform/runtime/fleet/adapters/agent.d.ts.map +1 -1
- package/dist/platform/runtime/fleet/adapters/agent.js +4 -4
- package/dist/platform/runtime/fleet/adapters/automation.d.ts +1 -1
- package/dist/platform/runtime/fleet/adapters/automation.js +1 -1
- package/dist/platform/runtime/fleet/adapters/code-index.d.ts +1 -1
- package/dist/platform/runtime/fleet/adapters/code-index.js +1 -1
- package/dist/platform/runtime/fleet/adapters/orchestration.js +1 -1
- package/dist/platform/runtime/fleet/adapters/schedule.d.ts +4 -4
- package/dist/platform/runtime/fleet/adapters/schedule.js +4 -4
- package/dist/platform/runtime/fleet/adapters/trigger.d.ts +3 -4
- package/dist/platform/runtime/fleet/adapters/trigger.d.ts.map +1 -1
- package/dist/platform/runtime/fleet/adapters/trigger.js +3 -4
- package/dist/platform/runtime/fleet/adapters/wrfc.js +1 -1
- package/dist/platform/runtime/fleet/registry.d.ts +7 -7
- package/dist/platform/runtime/fleet/registry.d.ts.map +1 -1
- package/dist/platform/runtime/fleet/registry.js +3 -3
- package/dist/platform/runtime/fleet/types.d.ts +9 -9
- package/dist/platform/runtime/fleet/types.d.ts.map +1 -1
- package/dist/platform/runtime/memory-spine/client.d.ts +127 -0
- package/dist/platform/runtime/memory-spine/client.d.ts.map +1 -0
- package/dist/platform/runtime/memory-spine/client.js +113 -0
- package/dist/platform/runtime/memory-spine/index.d.ts +11 -0
- package/dist/platform/runtime/memory-spine/index.d.ts.map +1 -0
- package/dist/platform/runtime/memory-spine/index.js +10 -0
- package/dist/platform/runtime/operator-client.d.ts +1 -1
- package/dist/platform/runtime/services.d.ts +6 -6
- package/dist/platform/runtime/services.d.ts.map +1 -1
- package/dist/platform/runtime/services.js +9 -9
- package/dist/platform/runtime/session-spine/union-cache.d.ts +1 -1
- package/dist/platform/runtime/session-spine/union-cache.js +1 -1
- package/dist/platform/state/canonical-memory.d.ts +7 -7
- package/dist/platform/state/canonical-memory.js +8 -8
- package/dist/platform/state/code-index-chunking.js +1 -1
- package/dist/platform/state/code-index-db.d.ts +1 -1
- package/dist/platform/state/code-index-store.js +1 -1
- package/dist/platform/state/index.d.ts +2 -2
- package/dist/platform/state/index.d.ts.map +1 -1
- package/dist/platform/state/index.js +1 -1
- package/dist/platform/state/memory-recall-contract.d.ts +59 -4
- package/dist/platform/state/memory-recall-contract.d.ts.map +1 -1
- package/dist/platform/state/memory-recall-contract.js +79 -3
- package/dist/platform/state/memory-registry.d.ts +8 -0
- package/dist/platform/state/memory-registry.d.ts.map +1 -1
- package/dist/platform/state/memory-registry.js +10 -0
- package/dist/platform/state/memory-vector-store.js +1 -1
- package/dist/platform/state/sqlite-vec-loader.d.ts +1 -1
- package/dist/platform/state/sqlite-vec-loader.js +1 -1
- package/dist/platform/state/vibe-projection.d.ts +3 -3
- package/dist/platform/state/vibe-projection.js +3 -3
- package/dist/platform/tools/agent/manager.d.ts +10 -10
- package/dist/platform/tools/agent/manager.js +7 -7
- package/dist/platform/tools/exec/runtime.js +5 -5
- package/dist/platform/tools/exec/schema.d.ts +1 -1
- package/dist/platform/tools/exec/schema.d.ts.map +1 -1
- package/dist/platform/tools/fetch/runtime.d.ts +1 -1
- package/dist/platform/tools/registry.d.ts +1 -1
- package/dist/platform/tools/registry.js +1 -1
- package/dist/platform/types/tools.d.ts +1 -1
- package/dist/platform/utils/request-body.d.ts.map +1 -1
- package/dist/platform/utils/request-body.js +50 -5
- package/dist/platform/version.js +1 -1
- package/package.json +13 -9
|
@@ -24,10 +24,11 @@ import { SDKErrorCodes } from '@pellux/goodvibes-errors';
|
|
|
24
24
|
import { ConversationManager } from '../core/conversation.js';
|
|
25
25
|
import { CompanionChatPersistence, defaultSessionsDir, } from './companion-chat-persistence.js';
|
|
26
26
|
import { buildProviderUserContent, buildReplayUserContent, resolveAttachments, } from './companion-chat-attachments.js';
|
|
27
|
+
import { activeMessages, applyEditBranch, planRegenerate, } from './companion-chat-branching.js';
|
|
28
|
+
import { executeCompanionToolCalls, runToolExhaustionFinalizer, } from './companion-chat-turn-execution.js';
|
|
27
29
|
import { planCompanionSweep } from './companion-chat-gc.js';
|
|
28
30
|
import { CompanionBrokerSync } from './companion-chat-broker-sync.js';
|
|
29
31
|
import { CompanionChatRateLimiter } from './companion-chat-rate-limiter.js';
|
|
30
|
-
import { executeToolCalls as executeOrchestratorToolCalls } from '../core/orchestrator-tool-runtime.js';
|
|
31
32
|
import { appendGoodVibesRuntimeAwarenessPrompt } from '../tools/goodvibes-runtime/index.js';
|
|
32
33
|
import { summarizeError } from '../utils/error-display.js';
|
|
33
34
|
import { logger } from '../utils/logger.js';
|
|
@@ -280,7 +281,7 @@ export class CompanionChatManager {
|
|
|
280
281
|
return updated;
|
|
281
282
|
}
|
|
282
283
|
/**
|
|
283
|
-
* Permanently delete a session (
|
|
284
|
+
* Permanently delete a session (see CHANGELOG 1.0.0: `delete` is now a genuine removal,
|
|
284
285
|
* distinct from `closeSession` above). Aborts any in-flight turn, removes
|
|
285
286
|
* the on-disk record file, and drops the in-memory entry — reusing
|
|
286
287
|
* {@link _hardRemove}, the SAME primitive the GC 'delete-persistent' sweep
|
|
@@ -500,11 +501,11 @@ export class CompanionChatManager {
|
|
|
500
501
|
completed = true;
|
|
501
502
|
break;
|
|
502
503
|
}
|
|
503
|
-
const toolResults = await this.
|
|
504
|
+
const toolResults = await executeCompanionToolCalls({ toolRegistry: this.toolRegistry, permissionManager: this.permissionManager, hookDispatcher: this.hookDispatcher, runtimeBus: this.runtimeBus }, toolCalls, publish, sessionId, turnId);
|
|
504
505
|
session.conversation.addToolResults(toolResults);
|
|
505
506
|
}
|
|
506
507
|
if (!completed && !abortSignal.aborted) {
|
|
507
|
-
const finalResponse = await this.
|
|
508
|
+
const finalResponse = await runToolExhaustionFinalizer({ provider: this.provider, finalizerPrompt: TOOL_EXHAUSTION_FINALIZER_PROMPT }, session, abortSignal, turnId, publish);
|
|
508
509
|
if (finalResponse.trim()) {
|
|
509
510
|
assistantContent += finalResponse;
|
|
510
511
|
session.conversation.addAssistantMessage(finalResponse);
|
|
@@ -560,85 +561,70 @@ export class CompanionChatManager {
|
|
|
560
561
|
}
|
|
561
562
|
}
|
|
562
563
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
case 'error':
|
|
583
|
-
throw new Error(chunk.error ?? 'Provider streaming error');
|
|
584
|
-
case 'tool_call':
|
|
585
|
-
case 'tool_result':
|
|
586
|
-
case 'done':
|
|
587
|
-
break;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return finalContent;
|
|
564
|
+
// ---------------------------------------------------------------------------
|
|
565
|
+
// Regenerate + edit-and-branch (honest lineage — see companion-chat-branching.ts)
|
|
566
|
+
// ---------------------------------------------------------------------------
|
|
567
|
+
/**
|
|
568
|
+
* Regenerate an assistant response: supersede the target assistant message (an
|
|
569
|
+
* explicit id, or the latest response) and everything after it — retained as
|
|
570
|
+
* history, never deleted — then re-run a fresh turn from the preceding user
|
|
571
|
+
* message. Refuses a closed (409 SESSION_CLOSED) or unknown (404
|
|
572
|
+
* SESSION_NOT_FOUND) session; honest code when there is nothing to regenerate.
|
|
573
|
+
*/
|
|
574
|
+
regenerateMessage(sessionId, input = {}) {
|
|
575
|
+
const session = this._requireOpenSession(sessionId);
|
|
576
|
+
this.rateLimiter?.check(sessionId, '');
|
|
577
|
+
const now = Date.now();
|
|
578
|
+
const plan = planRegenerate(session, input.messageId, now);
|
|
579
|
+
this._commitBranchAndRun(session, sessionId, plan.anchorUserMessageId, now);
|
|
580
|
+
const { regeneratedFrom, supersededMessageIds } = plan;
|
|
581
|
+
return { sessionId, regeneratedFrom, supersededMessageIds, turnStarted: true };
|
|
591
582
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
return toolResult;
|
|
613
|
-
});
|
|
583
|
+
/**
|
|
584
|
+
* Edit a user message and branch from it: supersede the target user message and
|
|
585
|
+
* everything after it (retained history), append a new user message carrying
|
|
586
|
+
* `revisionOf` back to the original, and run a fresh turn. Same closed/unknown
|
|
587
|
+
* refusals as {@link regenerateMessage}.
|
|
588
|
+
*/
|
|
589
|
+
editMessage(sessionId, input) {
|
|
590
|
+
const session = this._requireOpenSession(sessionId);
|
|
591
|
+
this.rateLimiter?.check(sessionId, '');
|
|
592
|
+
const now = Date.now();
|
|
593
|
+
const plan = applyEditBranch(session, sessionId, input, this.artifactStore, now);
|
|
594
|
+
this._commitBranchAndRun(session, sessionId, plan.newMessageId, now);
|
|
595
|
+
const { editedFrom, newMessageId, supersededMessageIds } = plan;
|
|
596
|
+
return { sessionId, editedFrom, messageId: newMessageId, supersededMessageIds, turnStarted: true };
|
|
597
|
+
}
|
|
598
|
+
/** Look up an active (open) session or throw the closed/not-found machine codes. */
|
|
599
|
+
_requireOpenSession(sessionId) {
|
|
600
|
+
const session = this.sessions.get(sessionId);
|
|
601
|
+
if (!session) {
|
|
602
|
+
throw Object.assign(new Error(`Session not found: ${sessionId}`), { code: 'SESSION_NOT_FOUND', status: 404 });
|
|
614
603
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
for (const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
type: 'turn.tool_result',
|
|
633
|
-
sessionId,
|
|
634
|
-
turnId,
|
|
635
|
-
toolCallId: call.id,
|
|
636
|
-
toolName: call.name,
|
|
637
|
-
result: toolResult.output ?? toolResult.error ?? null,
|
|
638
|
-
isError: !toolResult.success,
|
|
639
|
-
});
|
|
604
|
+
if (session.meta.status === 'closed') {
|
|
605
|
+
throw Object.assign(new Error('Session is closed'), { code: SDKErrorCodes.SESSION_CLOSED, status: 409 });
|
|
606
|
+
}
|
|
607
|
+
return session;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Shared tail of regenerate/edit: rebuild the LLM-facing conversation from the
|
|
611
|
+
* ACTIVE (non-superseded) chain (mirroring init()'s replay so the next turn
|
|
612
|
+
* sees only the live branch), persist, and fire the new turn.
|
|
613
|
+
*/
|
|
614
|
+
_commitBranchAndRun(session, sessionId, anchorUserMessageId, now) {
|
|
615
|
+
const conversation = new ConversationManager();
|
|
616
|
+
for (const msg of activeMessages(session.messages)) {
|
|
617
|
+
if (msg.role === 'user')
|
|
618
|
+
conversation.addUserMessage(buildReplayUserContent(msg));
|
|
619
|
+
else
|
|
620
|
+
conversation.addAssistantMessage(msg.content);
|
|
640
621
|
}
|
|
641
|
-
|
|
622
|
+
session.conversation = conversation;
|
|
623
|
+
this._updateMeta(session, { messageCount: session.messages.length, updatedAt: now });
|
|
624
|
+
this._persist(sessionId);
|
|
625
|
+
void this._runTurn(session, anchorUserMessageId).catch((error) => {
|
|
626
|
+
logger.warn('[companion-chat] branch turn execution failed', { sessionId, error: summarizeError(error) });
|
|
627
|
+
});
|
|
642
628
|
}
|
|
643
629
|
// ---------------------------------------------------------------------------
|
|
644
630
|
// GC sweep
|
|
@@ -712,7 +698,7 @@ export class CompanionChatManager {
|
|
|
712
698
|
/**
|
|
713
699
|
* Hard-remove a session's persisted file and in-memory record. The ONE
|
|
714
700
|
* removal code path — shared by {@link deleteSession} and the GC
|
|
715
|
-
* 'delete-persistent' action. Never fork this. Order matters
|
|
701
|
+
* 'delete-persistent' action. Never fork this. Order matters:
|
|
716
702
|
* drop the map entry, drain any in-flight {@link _persist} save for this
|
|
717
703
|
* id, THEN unlink — else a save mid-write from {@link closeSession} can
|
|
718
704
|
* resurrect the file post-unlink.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"companion-chat-routes.d.ts","sourceRoot":"","sources":["../../../src/platform/companion/companion-chat-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"companion-chat-routes.d.ts","sourceRoot":"","sources":["../../../src/platform/companion/companion-chat-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAYH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAMjF;;;GAGG;AACH,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAmE1B;AAgPD;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAMlF"}
|
|
@@ -64,6 +64,14 @@ export async function dispatchCompanionChatRoutes(req, context) {
|
|
|
64
64
|
if (sub === 'messages' && req.method === 'GET') {
|
|
65
65
|
return handleGetMessages(sessionId, context);
|
|
66
66
|
}
|
|
67
|
+
// POST /api/companion/chat/sessions/:sessionId/messages/retry (regenerate)
|
|
68
|
+
if (sub === 'messages/retry' && req.method === 'POST') {
|
|
69
|
+
return handleRegenerateMessage(req, sessionId, context);
|
|
70
|
+
}
|
|
71
|
+
// POST /api/companion/chat/sessions/:sessionId/messages/edit (edit + branch)
|
|
72
|
+
if (sub === 'messages/edit' && req.method === 'POST') {
|
|
73
|
+
return handleEditMessage(req, sessionId, context);
|
|
74
|
+
}
|
|
67
75
|
// GET /api/companion/chat/sessions/:sessionId/events
|
|
68
76
|
if (sub === 'events' && req.method === 'GET') {
|
|
69
77
|
return handleGetEvents(req, sessionId, context);
|
|
@@ -227,7 +235,7 @@ async function handleCloseSession(sessionId, context) {
|
|
|
227
235
|
return Response.json({ sessionId: session.id, status: session.status });
|
|
228
236
|
}
|
|
229
237
|
// ---------------------------------------------------------------------------
|
|
230
|
-
// DELETE /api/companion/chat/sessions/:sessionId (
|
|
238
|
+
// DELETE /api/companion/chat/sessions/:sessionId (see CHANGELOG 1.0.0: a real hard delete)
|
|
231
239
|
// ---------------------------------------------------------------------------
|
|
232
240
|
async function handleDeleteSession(sessionId, context) {
|
|
233
241
|
try {
|
|
@@ -333,6 +341,74 @@ async function handlePostMessage(req, sessionId, context) {
|
|
|
333
341
|
return Response.json({ error: e.message ?? 'Internal error', code: e.code ?? 'INTERNAL_ERROR' }, { status });
|
|
334
342
|
}
|
|
335
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Map a `{ code, status }`-carrying manager error to an honest JSON error
|
|
346
|
+
* response, mirroring the catch blocks used by the update/delete handlers.
|
|
347
|
+
*/
|
|
348
|
+
function respondWithManagerError(err) {
|
|
349
|
+
const e = err;
|
|
350
|
+
const status = e.status ?? 500;
|
|
351
|
+
return Response.json({ error: e.message ?? 'Internal error', code: e.code ?? 'INTERNAL_ERROR' }, { status });
|
|
352
|
+
}
|
|
353
|
+
// ---------------------------------------------------------------------------
|
|
354
|
+
// POST /api/companion/chat/sessions/:sessionId/messages/retry (regenerate)
|
|
355
|
+
// ---------------------------------------------------------------------------
|
|
356
|
+
/**
|
|
357
|
+
* Regenerate an assistant response. Optional `messageId` in the body targets a
|
|
358
|
+
* specific assistant message; omitted, the latest assistant response is re-run.
|
|
359
|
+
* The prior response is superseded (retained as history), never deleted.
|
|
360
|
+
*/
|
|
361
|
+
async function handleRegenerateMessage(req, sessionId, context) {
|
|
362
|
+
const bodyOrResponse = await context.parseOptionalJsonBody(req);
|
|
363
|
+
if (bodyOrResponse instanceof Response)
|
|
364
|
+
return bodyOrResponse;
|
|
365
|
+
const body = (bodyOrResponse ?? {});
|
|
366
|
+
const input = {
|
|
367
|
+
messageId: typeof body['messageId'] === 'string' ? body['messageId'] : undefined,
|
|
368
|
+
};
|
|
369
|
+
try {
|
|
370
|
+
return Response.json(context.chatManager.regenerateMessage(sessionId, input), { status: 202 });
|
|
371
|
+
}
|
|
372
|
+
catch (err) {
|
|
373
|
+
return respondWithManagerError(err);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
// ---------------------------------------------------------------------------
|
|
377
|
+
// POST /api/companion/chat/sessions/:sessionId/messages/edit (edit + branch)
|
|
378
|
+
// ---------------------------------------------------------------------------
|
|
379
|
+
/**
|
|
380
|
+
* Edit a user message and branch the conversation from it. Accepts `messageId`
|
|
381
|
+
* (required) plus the edited text as `body` or `content` (as the message-post
|
|
382
|
+
* route does). The original message and everything after it are superseded
|
|
383
|
+
* (retained as history) and a fresh turn runs from the edited message.
|
|
384
|
+
*/
|
|
385
|
+
async function handleEditMessage(req, sessionId, context) {
|
|
386
|
+
const bodyOrResponse = await context.parseJsonBody(req);
|
|
387
|
+
if (bodyOrResponse instanceof Response)
|
|
388
|
+
return bodyOrResponse;
|
|
389
|
+
const body = bodyOrResponse;
|
|
390
|
+
const messageId = typeof body['messageId'] === 'string' ? body['messageId'].trim() : '';
|
|
391
|
+
if (!messageId) {
|
|
392
|
+
return Response.json({ error: 'messageId is required', code: 'INVALID_INPUT' }, { status: 400 });
|
|
393
|
+
}
|
|
394
|
+
const attachments = readCompanionChatAttachments(body);
|
|
395
|
+
if (attachments instanceof Response)
|
|
396
|
+
return attachments;
|
|
397
|
+
const input = {
|
|
398
|
+
messageId,
|
|
399
|
+
content: readCompanionChatMessageBody(body),
|
|
400
|
+
attachments,
|
|
401
|
+
metadata: typeof body['metadata'] === 'object' && body['metadata'] !== null
|
|
402
|
+
? body['metadata']
|
|
403
|
+
: undefined,
|
|
404
|
+
};
|
|
405
|
+
try {
|
|
406
|
+
return Response.json(context.chatManager.editMessage(sessionId, input), { status: 202 });
|
|
407
|
+
}
|
|
408
|
+
catch (err) {
|
|
409
|
+
return respondWithManagerError(err);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
336
412
|
// ---------------------------------------------------------------------------
|
|
337
413
|
// GET /api/companion/chat/sessions/:sessionId/messages
|
|
338
414
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* companion-chat-turn-execution.ts
|
|
3
|
+
*
|
|
4
|
+
* The two turn-execution helpers used by CompanionChatManager._runTurn, split
|
|
5
|
+
* out of companion-chat-manager.ts (see CHANGELOG) so the manager stays under
|
|
6
|
+
* the repo's hand-authored file-size cap while regenerate/edit verbs are added.
|
|
7
|
+
* These are a pure move: the logic is unchanged, the manager now passes the
|
|
8
|
+
* dependencies it used to reach through `this`.
|
|
9
|
+
*
|
|
10
|
+
* - runToolExhaustionFinalizer: after the tool-call budget is exhausted, run one
|
|
11
|
+
* more streamed turn that is instructed not to call tools, returning its text.
|
|
12
|
+
* - executeCompanionToolCalls: execute model-emitted tool calls through the
|
|
13
|
+
* permission boundary and publish per-call results, degrading honestly when a
|
|
14
|
+
* registry is present without a permission manager.
|
|
15
|
+
*/
|
|
16
|
+
import type { ConversationManager } from '../core/conversation.js';
|
|
17
|
+
import type { CompanionChatTurnEvent } from './companion-chat-types.js';
|
|
18
|
+
import type { CompanionLLMProvider } from './companion-chat-manager.js';
|
|
19
|
+
import type { ToolRegistry } from '../tools/registry.js';
|
|
20
|
+
import type { ToolCall, ToolResult } from '../types/tools.js';
|
|
21
|
+
import type { PermissionManager } from '../permissions/manager.js';
|
|
22
|
+
import type { RuntimeEventBus } from '../runtime/events/index.js';
|
|
23
|
+
import type { HookEvent, HookResult } from '../hooks/types.js';
|
|
24
|
+
type HookDispatcherLike = {
|
|
25
|
+
fire(event: HookEvent): Promise<HookResult>;
|
|
26
|
+
};
|
|
27
|
+
/** The minimal session shape the finalizer needs (avoids importing the private InternalSession). */
|
|
28
|
+
interface FinalizerSession {
|
|
29
|
+
readonly meta: {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly model: string | null;
|
|
32
|
+
readonly provider: string | null;
|
|
33
|
+
readonly systemPrompt: string | null;
|
|
34
|
+
};
|
|
35
|
+
readonly conversation: ConversationManager;
|
|
36
|
+
}
|
|
37
|
+
export interface ToolExhaustionFinalizerDeps {
|
|
38
|
+
readonly provider: CompanionLLMProvider;
|
|
39
|
+
/** The pre-built finalizer system prompt (kept in the manager alongside its round cap). */
|
|
40
|
+
readonly finalizerPrompt: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Run a single streamed turn after the per-turn tool-call budget is exhausted,
|
|
44
|
+
* instructing the model not to call more tools, and return the collected text.
|
|
45
|
+
*/
|
|
46
|
+
export declare function runToolExhaustionFinalizer(deps: ToolExhaustionFinalizerDeps, session: FinalizerSession, abortSignal: AbortSignal, turnId: string, publish: (event: CompanionChatTurnEvent) => void): Promise<string>;
|
|
47
|
+
export interface CompanionToolExecutionDeps {
|
|
48
|
+
readonly toolRegistry: ToolRegistry | null;
|
|
49
|
+
readonly permissionManager: PermissionManager | null;
|
|
50
|
+
readonly hookDispatcher: HookDispatcherLike | null;
|
|
51
|
+
readonly runtimeBus: RuntimeEventBus | null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Execute model-emitted tool calls through the permission boundary and publish
|
|
55
|
+
* each result. Returns [] when no registry is configured; denies every call
|
|
56
|
+
* honestly (isError result + published event) when a registry exists without a
|
|
57
|
+
* permission manager.
|
|
58
|
+
*/
|
|
59
|
+
export declare function executeCompanionToolCalls(deps: CompanionToolExecutionDeps, toolCalls: ToolCall[], publish: (event: CompanionChatTurnEvent) => void, sessionId: string, turnId: string): Promise<ToolResult[]>;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=companion-chat-turn-execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"companion-chat-turn-execution.d.ts","sourceRoot":"","sources":["../../../src/platform/companion/companion-chat-turn-execution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CA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UAAU,EAAE,eAAe,GAAG,IAAI,CAAC;CAC7C;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,0BAA0B,EAChC,SAAS,EAAE,QAAQ,EAAE,EACrB,OAAO,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,EAChD,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,EAAE,CAAC,CAoDvB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* companion-chat-turn-execution.ts
|
|
3
|
+
*
|
|
4
|
+
* The two turn-execution helpers used by CompanionChatManager._runTurn, split
|
|
5
|
+
* out of companion-chat-manager.ts (see CHANGELOG) so the manager stays under
|
|
6
|
+
* the repo's hand-authored file-size cap while regenerate/edit verbs are added.
|
|
7
|
+
* These are a pure move: the logic is unchanged, the manager now passes the
|
|
8
|
+
* dependencies it used to reach through `this`.
|
|
9
|
+
*
|
|
10
|
+
* - runToolExhaustionFinalizer: after the tool-call budget is exhausted, run one
|
|
11
|
+
* more streamed turn that is instructed not to call tools, returning its text.
|
|
12
|
+
* - executeCompanionToolCalls: execute model-emitted tool calls through the
|
|
13
|
+
* permission boundary and publish per-call results, degrading honestly when a
|
|
14
|
+
* registry is present without a permission manager.
|
|
15
|
+
*/
|
|
16
|
+
import { executeToolCalls as executeOrchestratorToolCalls } from '../core/orchestrator-tool-runtime.js';
|
|
17
|
+
import { appendGoodVibesRuntimeAwarenessPrompt } from '../tools/goodvibes-runtime/index.js';
|
|
18
|
+
/**
|
|
19
|
+
* Run a single streamed turn after the per-turn tool-call budget is exhausted,
|
|
20
|
+
* instructing the model not to call more tools, and return the collected text.
|
|
21
|
+
*/
|
|
22
|
+
export async function runToolExhaustionFinalizer(deps, session, abortSignal, turnId, publish) {
|
|
23
|
+
const sessionId = session.meta.id;
|
|
24
|
+
let finalContent = '';
|
|
25
|
+
const stream = deps.provider.chatStream([...session.conversation.getMessagesForLLM()], {
|
|
26
|
+
systemPrompt: appendGoodVibesRuntimeAwarenessPrompt([session.meta.systemPrompt, deps.finalizerPrompt].filter(Boolean).join('\n\n')),
|
|
27
|
+
model: session.meta.model,
|
|
28
|
+
provider: session.meta.provider,
|
|
29
|
+
abortSignal,
|
|
30
|
+
});
|
|
31
|
+
for await (const chunk of stream) {
|
|
32
|
+
if (abortSignal.aborted)
|
|
33
|
+
break;
|
|
34
|
+
switch (chunk.type) {
|
|
35
|
+
case 'text_delta': {
|
|
36
|
+
const delta = chunk.delta ?? '';
|
|
37
|
+
finalContent += delta;
|
|
38
|
+
publish({ type: 'turn.delta', sessionId, turnId, delta });
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 'error':
|
|
42
|
+
throw new Error(chunk.error ?? 'Provider streaming error');
|
|
43
|
+
case 'tool_call':
|
|
44
|
+
case 'tool_result':
|
|
45
|
+
case 'done':
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return finalContent;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Execute model-emitted tool calls through the permission boundary and publish
|
|
53
|
+
* each result. Returns [] when no registry is configured; denies every call
|
|
54
|
+
* honestly (isError result + published event) when a registry exists without a
|
|
55
|
+
* permission manager.
|
|
56
|
+
*/
|
|
57
|
+
export async function executeCompanionToolCalls(deps, toolCalls, publish, sessionId, turnId) {
|
|
58
|
+
const toolRegistry = deps.toolRegistry;
|
|
59
|
+
if (!toolRegistry)
|
|
60
|
+
return [];
|
|
61
|
+
if (!deps.permissionManager) {
|
|
62
|
+
return toolCalls.map((call) => {
|
|
63
|
+
const toolResult = {
|
|
64
|
+
callId: call.id,
|
|
65
|
+
success: false,
|
|
66
|
+
error: 'Tool execution denied: permission manager unavailable for companion chat',
|
|
67
|
+
};
|
|
68
|
+
publish({
|
|
69
|
+
type: 'turn.tool_result',
|
|
70
|
+
sessionId,
|
|
71
|
+
turnId,
|
|
72
|
+
toolCallId: call.id,
|
|
73
|
+
toolName: call.name,
|
|
74
|
+
result: toolResult.error,
|
|
75
|
+
isError: true,
|
|
76
|
+
});
|
|
77
|
+
return toolResult;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const results = await executeOrchestratorToolCalls({
|
|
81
|
+
toolRegistry,
|
|
82
|
+
permissionManager: deps.permissionManager,
|
|
83
|
+
hookDispatcher: deps.hookDispatcher,
|
|
84
|
+
runtimeBus: deps.runtimeBus,
|
|
85
|
+
sessionId,
|
|
86
|
+
emitterContext: (id) => ({
|
|
87
|
+
sessionId,
|
|
88
|
+
traceId: `${sessionId}:${id}`,
|
|
89
|
+
source: 'companion-chat',
|
|
90
|
+
}),
|
|
91
|
+
}, turnId, toolCalls);
|
|
92
|
+
for (const [index, toolResult] of results.entries()) {
|
|
93
|
+
const call = toolCalls[index];
|
|
94
|
+
if (!call)
|
|
95
|
+
continue;
|
|
96
|
+
publish({
|
|
97
|
+
type: 'turn.tool_result',
|
|
98
|
+
sessionId,
|
|
99
|
+
turnId,
|
|
100
|
+
toolCallId: call.id,
|
|
101
|
+
toolName: call.name,
|
|
102
|
+
result: toolResult.output ?? toolResult.error ?? null,
|
|
103
|
+
isError: !toolResult.success,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return results;
|
|
107
|
+
}
|
|
@@ -26,6 +26,21 @@ export interface CompanionChatMessageAttachment extends ArtifactDescriptor {
|
|
|
26
26
|
readonly artifactId: string;
|
|
27
27
|
readonly label?: string | undefined;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Why a message was superseded. A superseded message is NEVER deleted — it is
|
|
31
|
+
* retained in the message list and on disk, flagged so a client can tell the
|
|
32
|
+
* active conversation chain from the retained history behind a regenerate or an
|
|
33
|
+
* edit. This is the honest-lineage contract: regenerating a response or editing
|
|
34
|
+
* a message forks the conversation and keeps the old branch retrievable, it does
|
|
35
|
+
* not silently drop it.
|
|
36
|
+
*
|
|
37
|
+
* - `regenerate` — the assistant response was re-run; this is the previous
|
|
38
|
+
* response (and any turns that followed it), kept as history.
|
|
39
|
+
* - `edit` — the user edited an earlier message and the conversation branched
|
|
40
|
+
* from there; this is the original message (or a turn after the edit point),
|
|
41
|
+
* kept as history.
|
|
42
|
+
*/
|
|
43
|
+
export type CompanionChatSupersededReason = 'regenerate' | 'edit';
|
|
29
44
|
export interface CompanionChatMessage {
|
|
30
45
|
readonly id: string;
|
|
31
46
|
readonly sessionId: string;
|
|
@@ -34,6 +49,21 @@ export interface CompanionChatMessage {
|
|
|
34
49
|
readonly attachments: readonly CompanionChatMessageAttachment[];
|
|
35
50
|
readonly metadata?: Record<string, unknown> | undefined;
|
|
36
51
|
readonly createdAt: number;
|
|
52
|
+
/**
|
|
53
|
+
* Timestamp at which this message was superseded by a regenerate or an edit.
|
|
54
|
+
* Absent = the message is part of the active conversation chain. Present = the
|
|
55
|
+
* message is retained history behind a fork (still returned by list/get, never
|
|
56
|
+
* removed), so nothing is silently lost.
|
|
57
|
+
*/
|
|
58
|
+
readonly supersededAt?: number | undefined;
|
|
59
|
+
/** Why this message was superseded (only set together with `supersededAt`). */
|
|
60
|
+
readonly supersededReason?: CompanionChatSupersededReason | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* On a replacement message, the id of the message it replaces: the new user
|
|
63
|
+
* message points back at the original it was edited from, giving an explicit
|
|
64
|
+
* forward lineage link in addition to the `supersededAt` marker on the old one.
|
|
65
|
+
*/
|
|
66
|
+
readonly revisionOf?: string | undefined;
|
|
37
67
|
}
|
|
38
68
|
export interface CompanionChatSession {
|
|
39
69
|
readonly id: string;
|
|
@@ -92,6 +122,43 @@ export interface GetCompanionChatSessionOutput {
|
|
|
92
122
|
readonly session: CompanionChatSession;
|
|
93
123
|
readonly messages: CompanionChatMessage[];
|
|
94
124
|
}
|
|
125
|
+
export interface RegenerateCompanionChatMessageInput {
|
|
126
|
+
/**
|
|
127
|
+
* The assistant message to regenerate. Omit to regenerate the latest assistant
|
|
128
|
+
* response. The referenced message and any messages after it are superseded
|
|
129
|
+
* (retained as history), then a fresh turn re-runs from the preceding user
|
|
130
|
+
* message.
|
|
131
|
+
*/
|
|
132
|
+
readonly messageId?: string | undefined;
|
|
133
|
+
}
|
|
134
|
+
export interface RegenerateCompanionChatMessageOutput {
|
|
135
|
+
readonly sessionId: string;
|
|
136
|
+
/** The assistant message id whose turn was re-run (now superseded, still retrievable). */
|
|
137
|
+
readonly regeneratedFrom: string;
|
|
138
|
+
/** Every message id superseded by this regenerate — retained history, never deleted. */
|
|
139
|
+
readonly supersededMessageIds: readonly string[];
|
|
140
|
+
/** True when a new turn was started to produce the replacement response. */
|
|
141
|
+
readonly turnStarted: boolean;
|
|
142
|
+
}
|
|
143
|
+
export interface EditCompanionChatMessageInput {
|
|
144
|
+
/** The user message to edit and branch from. Required. */
|
|
145
|
+
readonly messageId: string;
|
|
146
|
+
/** The edited message text. Required (unless attachments carry the content). */
|
|
147
|
+
readonly content: string;
|
|
148
|
+
readonly attachments?: readonly CompanionChatMessageAttachmentInput[] | undefined;
|
|
149
|
+
readonly metadata?: Record<string, unknown> | undefined;
|
|
150
|
+
}
|
|
151
|
+
export interface EditCompanionChatMessageOutput {
|
|
152
|
+
readonly sessionId: string;
|
|
153
|
+
/** The original user message id that was edited (now superseded, still retrievable). */
|
|
154
|
+
readonly editedFrom: string;
|
|
155
|
+
/** The id of the new user message carrying the edited content. */
|
|
156
|
+
readonly messageId: string;
|
|
157
|
+
/** Every message id superseded by this edit — retained history, never deleted. */
|
|
158
|
+
readonly supersededMessageIds: readonly string[];
|
|
159
|
+
/** True when a new turn was started to answer the edited message. */
|
|
160
|
+
readonly turnStarted: boolean;
|
|
161
|
+
}
|
|
95
162
|
export interface CompanionChatTurnStartedEvent {
|
|
96
163
|
readonly type: 'turn.started';
|
|
97
164
|
readonly sessionId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"companion-chat-types.d.ts","sourceRoot":"","sources":["../../../src/platform/companion/companion-chat-types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AC,QAAQ,EAAE,2BAA2B,CAAC;CAChD;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,sBAAsB,GAC9B,6BAA6B,GAC7B,2BAA2B,GAC3B,8BAA8B,GAC9B,gCAAgC,GAChC,+BAA+B,GAC/B,2BAA2B,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* credential-status.ts
|
|
3
3
|
*
|
|
4
4
|
* Promotes the internal SecretsManager to a secret-FREE status source for the
|
|
5
|
-
* daemon's `credentials.get` wire method (
|
|
5
|
+
* daemon's `credentials.get` wire method (config sharing, see CHANGELOG 1.0.0).
|
|
6
6
|
*
|
|
7
7
|
* The returned provider reports whether each credential in the shared store is
|
|
8
8
|
* configured and usable — it NEVER exposes the plaintext value. `usable` is a
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* credential-status.ts
|
|
3
3
|
*
|
|
4
4
|
* Promotes the internal SecretsManager to a secret-FREE status source for the
|
|
5
|
-
* daemon's `credentials.get` wire method (
|
|
5
|
+
* daemon's `credentials.get` wire method (config sharing, see CHANGELOG 1.0.0).
|
|
6
6
|
*
|
|
7
7
|
* The returned provider reports whether each credential in the shared store is
|
|
8
8
|
* configured and usable — it NEVER exposes the plaintext value. `usable` is a
|
|
@@ -33,7 +33,7 @@ export interface DaemonEnabledReader {
|
|
|
33
33
|
*
|
|
34
34
|
* `daemon.enabled` governs (default `true` — daemon on by default,
|
|
35
35
|
* loopback-bound). The deprecated `danger.daemon` alias that used to
|
|
36
|
-
* override this was removed in
|
|
36
|
+
* override this was removed in CHANGELOG 1.0.0 (its explicit-`false` off-switch is
|
|
37
37
|
* preserved for existing users by a one-time config migration onto
|
|
38
38
|
* `daemon.enabled`, applied at {@link ConfigManager.load} — see migrations.ts).
|
|
39
39
|
*
|
|
@@ -28,7 +28,7 @@ export function isAutoApproveEnabled(configManager) {
|
|
|
28
28
|
*
|
|
29
29
|
* `daemon.enabled` governs (default `true` — daemon on by default,
|
|
30
30
|
* loopback-bound). The deprecated `danger.daemon` alias that used to
|
|
31
|
-
* override this was removed in
|
|
31
|
+
* override this was removed in CHANGELOG 1.0.0 (its explicit-`false` off-switch is
|
|
32
32
|
* preserved for existing users by a one-time config migration onto
|
|
33
33
|
* `daemon.enabled`, applied at {@link ConfigManager.load} — see migrations.ts).
|
|
34
34
|
*
|
|
@@ -96,7 +96,7 @@ export declare class ConfigManager {
|
|
|
96
96
|
/** Load config from disk: global then project (project wins). Deep-merges with defaults. */
|
|
97
97
|
load(): void;
|
|
98
98
|
/**
|
|
99
|
-
* Removal-of-`danger.daemon` migration (
|
|
99
|
+
* Removal-of-`danger.daemon` migration (see CHANGELOG 1.0.0): rewrite an explicit legacy
|
|
100
100
|
* `danger.daemon = false` onto `daemon.enabled = false` before the raw JSON
|
|
101
101
|
* is merged with defaults, so the removed alias's two-year off-switch is
|
|
102
102
|
* honored rather than silently flipped on. Reports honestly via the logger
|