@oscharko-dev/keiko-server 0.2.6 → 0.2.8
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/.tsbuildinfo +1 -1
- package/dist/chat-compaction-evidence.d.ts +12 -0
- package/dist/chat-compaction-evidence.d.ts.map +1 -0
- package/dist/chat-compaction-evidence.js +46 -0
- package/dist/chat-handlers.d.ts +16 -0
- package/dist/chat-handlers.d.ts.map +1 -1
- package/dist/chat-handlers.js +78 -28
- package/dist/chat-stream-handlers.d.ts.map +1 -1
- package/dist/chat-stream-handlers.js +13 -1
- package/dist/conversation-compaction.d.ts +12 -0
- package/dist/conversation-compaction.d.ts.map +1 -0
- package/dist/conversation-compaction.js +102 -0
- package/dist/deps.d.ts +3 -0
- package/dist/deps.d.ts.map +1 -1
- package/dist/deps.js +3 -2
- package/dist/files.d.ts +18 -0
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +174 -0
- package/dist/gateway-readiness.d.ts +6 -0
- package/dist/gateway-readiness.d.ts.map +1 -0
- package/dist/gateway-readiness.js +624 -0
- package/dist/grounded-context-diagnostics.d.ts +5 -0
- package/dist/grounded-context-diagnostics.d.ts.map +1 -0
- package/dist/grounded-context-diagnostics.js +77 -0
- package/dist/grounded-orchestrator.d.ts +2 -0
- package/dist/grounded-orchestrator.d.ts.map +1 -1
- package/dist/grounded-orchestrator.js +122 -53
- package/dist/grounded-qa-hybrid.d.ts.map +1 -1
- package/dist/grounded-qa-hybrid.js +7 -4
- package/dist/grounded-qa-multi-source.d.ts.map +1 -1
- package/dist/grounded-qa-multi-source.js +49 -2
- package/dist/grounded-qa.d.ts +4 -0
- package/dist/grounded-qa.d.ts.map +1 -1
- package/dist/grounded-qa.js +36 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/local-knowledge-grounded-qa.d.ts.map +1 -1
- package/dist/local-knowledge-grounded-qa.js +11 -2
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +5 -10
- package/dist/run-handlers.d.ts +0 -1
- package/dist/run-handlers.d.ts.map +1 -1
- package/dist/run-handlers.js +0 -217
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +2 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/messages.d.ts +2 -1
- package/dist/store/messages.d.ts.map +1 -1
- package/dist/store/messages.js +46 -4
- package/dist/store/schema.d.ts +1 -1
- package/dist/store/schema.d.ts.map +1 -1
- package/dist/store/schema.js +7 -1
- package/dist/store/types.d.ts +3 -2
- package/dist/store/types.d.ts.map +1 -1
- package/package.json +19 -19
- package/dist/grounded-handoff.d.ts +0 -4
- package/dist/grounded-handoff.d.ts.map +0 -1
- package/dist/grounded-handoff.js +0 -445
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grounded-qa.d.ts","sourceRoot":"","sources":["../src/grounded-qa.ts"],"names":[],"mappings":"AAUA,OAAO,EAOL,KAAK,WAAW,IAAI,kBAAkB,EAEvC,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"grounded-qa.d.ts","sourceRoot":"","sources":["../src/grounded-qa.ts"],"names":[],"mappings":"AAUA,OAAO,EAOL,KAAK,WAAW,IAAI,kBAAkB,EAEvC,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,8BAA8B,CAAC;AAQtC,OAAO,EAGL,KAAK,oBAAoB,EAEzB,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAIL,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACzB,MAAM,wCAAwC,CAAC;AAGhD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEzD,OAA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AAgB,uBAAuB,CACrC,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,GACvB,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,CAmBrC;AASD,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,gBAAgB,CAAC,EAC3C,IAAI,EAAE,oBAAoB,GACzB,IAAI,CAAC,6BAA6B,EAAE,iBAAiB,CAAC,CAMxD;AAQD,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,gBAAgB,CAAC,EAC3C,IAAI,EAAE,oBAAoB,GACzB,UAAU,CAAC,OAAO,6BAA6B,CAAC,GAAG,SAAS,CAM9D;AA+KD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;CACxC;AAmID,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC;IAC3C,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAC/C,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;CAClC;AA8CD,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,aAAa,EACnB,MAAM,CAAC,EAAE,cAAc,EACvB,WAAW,CAAC,EAAE,eAAe,EAC7B,MAAM,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,WAAW,CAAC,CAsCtB"}
|
package/dist/grounded-qa.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
7
7
|
import { realpathSync } from "node:fs";
|
|
8
8
|
import { basename } from "node:path";
|
|
9
9
|
import { CancelledError, ContextOverflowError, GatewayError, findCapability, findConfiguredCapability, resolveCostClass, } from "@oscharko-dev/keiko-model-gateway";
|
|
10
|
-
import { persistConnectedContextEvidence } from "@oscharko-dev/keiko-evidence";
|
|
10
|
+
import { persistConnectedContextEvidence, } from "@oscharko-dev/keiko-evidence";
|
|
11
11
|
import { redact } from "@oscharko-dev/keiko-security";
|
|
12
12
|
import { RepoSearchInvalidQueryError, RepoSearchInvalidRangeError, RepoSearchUnsupportedFileError, } from "@oscharko-dev/keiko-workspace";
|
|
13
13
|
import { CONNECTED_CONTEXT_SCHEMA_VERSION, validateConnectedContextPack, } from "@oscharko-dev/keiko-contracts/connected-context";
|
|
@@ -17,6 +17,7 @@ import { errorBody } from "./routes.js";
|
|
|
17
17
|
import { currentGatewayConfig, currentGroundingLimits, currentRedactionSecrets } from "./deps.js";
|
|
18
18
|
import { ClarificationNeededError, clarificationUserMessage, runGroundedExploration, } from "./grounded-orchestrator.js";
|
|
19
19
|
import { microIndexForGroundedScope } from "./grounded-context-index.js";
|
|
20
|
+
import { deriveGroundedContextAssembly } from "./grounded-context-diagnostics.js";
|
|
20
21
|
import { pathIsDenied } from "./files-deny.js";
|
|
21
22
|
import { handleLocalKnowledgeGroundedAsk } from "./local-knowledge-grounded-qa.js";
|
|
22
23
|
import { buildConnectedScopes, createMultiSourceAnswerer, defaultRetriever, runMultiSourceAsk, } from "./grounded-qa-multi-source.js";
|
|
@@ -507,6 +508,10 @@ function defaultRunner(deps, modelId, signal) {
|
|
|
507
508
|
nowMs,
|
|
508
509
|
signal,
|
|
509
510
|
microIndex: microIndexForGroundedScope(input.scope, nowMs),
|
|
511
|
+
// ADR-0055 D1/D5 (PR4-W1): thread the provisioned profile so the diagnostics observer fires
|
|
512
|
+
// on the assembled pack. exactOptionalPropertyTypes — omit the key entirely when absent so
|
|
513
|
+
// the legacy no-profile path stays byte-identical (observer guard never sees a key).
|
|
514
|
+
...(deps.contextProfile === undefined ? {} : { contextProfile: deps.contextProfile }),
|
|
510
515
|
});
|
|
511
516
|
};
|
|
512
517
|
}
|
|
@@ -573,6 +578,33 @@ export function persistGroundedExchange(deps, chatId, userContent, assistantCont
|
|
|
573
578
|
}
|
|
574
579
|
return [user, assistant];
|
|
575
580
|
}
|
|
581
|
+
// ADR-0056 W3: regulated EvidenceManifest.contextAssembly? producer for the grounded persist
|
|
582
|
+
// path. Returns the conditional-spread fragment for ConnectedContextEvidenceInput. The field is
|
|
583
|
+
// emitted ONLY when a ContextProfile was threaded (deps.contextProfile) AND the observer ran on
|
|
584
|
+
// this pack (pack.diagnostics?.contextBudget present — the same precondition the PR4 observer
|
|
585
|
+
// records). When either is absent the fragment is empty, so the manifest is byte-identical to
|
|
586
|
+
// today (exactOptionalPropertyTypes: omit, never set to undefined). Shared by all three grounded
|
|
587
|
+
// persist sites (single / multi-source / hybrid) so the gate logic cannot diverge.
|
|
588
|
+
export function groundedContextAssemblyInput(deps, pack) {
|
|
589
|
+
const profile = deps.contextProfile;
|
|
590
|
+
if (profile === undefined || pack.diagnostics?.contextBudget === undefined) {
|
|
591
|
+
return {};
|
|
592
|
+
}
|
|
593
|
+
return { contextAssembly: deriveGroundedContextAssembly(pack, profile) };
|
|
594
|
+
}
|
|
595
|
+
// ADR-0057 D1: the path-free BFF wire-summary projection. Returns the same
|
|
596
|
+
// ContextAssemblyDiagnostics the evidence path derives (one shared derivation, no divergence) so
|
|
597
|
+
// buildGroundedAnswerContextPackSummary can project a counts-only contextSummary into the
|
|
598
|
+
// browser-visible wire shape. Gated identically to groundedContextAssemblyInput: present ONLY when
|
|
599
|
+
// a ContextProfile is active AND the observer ran (pack.diagnostics?.contextBudget). When absent
|
|
600
|
+
// the builder is called with three args and returns a byte-identical summary (no contextSummary).
|
|
601
|
+
export function groundedContextSummaryInput(deps, pack) {
|
|
602
|
+
const profile = deps.contextProfile;
|
|
603
|
+
if (profile === undefined || pack.diagnostics?.contextBudget === undefined) {
|
|
604
|
+
return undefined;
|
|
605
|
+
}
|
|
606
|
+
return deriveGroundedContextAssembly(pack, profile);
|
|
607
|
+
}
|
|
576
608
|
function persistGroundedAuditEvidence(workerCtx, output, citationCount) {
|
|
577
609
|
const finishedAt = Date.now();
|
|
578
610
|
const startedAt = Math.max(0, finishedAt - output.elapsedMs);
|
|
@@ -591,6 +623,7 @@ function persistGroundedAuditEvidence(workerCtx, output, citationCount) {
|
|
|
591
623
|
elapsedMs: output.elapsedMs,
|
|
592
624
|
startedAt,
|
|
593
625
|
finishedAt,
|
|
626
|
+
...groundedContextAssemblyInput(workerCtx.deps, output.pack),
|
|
594
627
|
}, {
|
|
595
628
|
store: workerCtx.deps.evidenceStore,
|
|
596
629
|
env: workerCtx.deps.env,
|
|
@@ -619,7 +652,7 @@ async function runAsk(workerCtx) {
|
|
|
619
652
|
const citations = buildCitations(output.pack, deps.redactor);
|
|
620
653
|
const evidenceRunId = persistGroundedAuditEvidence(workerCtx, output, citations.length);
|
|
621
654
|
const [userMessage, assistantMessage] = persistGroundedExchange(deps, chat.id, userContent, assistantContent);
|
|
622
|
-
const contextPack = buildGroundedAnswerContextPackSummary(output.pack, citations.length, output.elapsedMs);
|
|
655
|
+
const contextPack = buildGroundedAnswerContextPackSummary(output.pack, citations.length, output.elapsedMs, groundedContextSummaryInput(deps, output.pack));
|
|
623
656
|
const answer = {
|
|
624
657
|
groundingKind: "connected-context",
|
|
625
658
|
userMessageId: userMessage.id,
|
|
@@ -632,6 +665,7 @@ async function runAsk(workerCtx) {
|
|
|
632
665
|
elapsedMs: output.elapsedMs,
|
|
633
666
|
contextPack,
|
|
634
667
|
};
|
|
668
|
+
deps.store.attachGroundedAnswer(assistantMessage.id, answer);
|
|
635
669
|
rememberGroundedTurn({
|
|
636
670
|
assistantMessageId: assistantMessage.id,
|
|
637
671
|
chatId: chat.id,
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export { runMemoryMaintenance, type MaintenanceCounts } from "./memory-maintenan
|
|
|
21
21
|
export { exportMemoryDiagnostics, type ExportMemoryDiagnosticsOptions, type MemoryDiagnostics, type MemoryScopeCount, type MemoryStatusHistogram, } from "./memory-diagnostics.js";
|
|
22
22
|
export { createMemoryEmbedder, selectMemoryEmbeddingModelId, type MemoryEmbedder, } from "./memory-embedding.js";
|
|
23
23
|
export { buildTerminalEvidenceEntry, appendTerminalEvidence, type TerminalEvidenceEntry, } from "./terminal-evidence.js";
|
|
24
|
-
export { handleFilesContent, listFilesDirectories, readFilesContent, readFilesPreview, readFilesTree, writeFilesContent, type FilesContentResponse, type FilesDirectoryEntry, type FilesDirectoryListing, type FilesDirectoryRoot, type FilesEntryKind, type FilesPreviewResponse, type FilesTreeEntry, type FilesTreeResponse, } from "./files.js";
|
|
24
|
+
export { handleFilesContent, handleFilesSearch, listFilesDirectories, readFilesContent, readFilesPreview, readFilesTree, searchFiles, writeFilesContent, type FilesContentResponse, type FilesDirectoryEntry, type FilesDirectoryListing, type FilesDirectoryRoot, type FilesEntryKind, type FilesSearchResponse, type FilesSearchResult, type FilesPreviewResponse, type FilesTreeEntry, type FilesTreeResponse, } from "./files.js";
|
|
25
|
+
export { conversationForGateway, MAX_CONTEXT_MESSAGES, type GatewayConversationMessage, } from "./chat-handlers.js";
|
|
26
|
+
export { conversationForGatewayWithCompaction, type ConversationCompactionOptions, type ConversationCompactionOutcome, } from "./conversation-compaction.js";
|
|
25
27
|
export { handlePromptEnhancement, buildPromptEnhancementRecordInput, runPromptEnhancement, PromptEnhancementCancelledError, PromptEnhancementInputError, type RunPromptEnhancementDeps, } from "./promptEnhancer/index.js";
|
|
26
28
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,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AK,6BAA6B,GACnC,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EACL,uBAAuB,EACvB,iCAAiC,EACjC,oBAAoB,EACpB,+BAA+B,EAC/B,2BAA2B,EAC3B,KAAK,wBAAwB,GAC9B,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,12 @@ export { runMemoryMaintenance } from "./memory-maintenance-handlers.js";
|
|
|
26
26
|
export { exportMemoryDiagnostics, } from "./memory-diagnostics.js";
|
|
27
27
|
export { createMemoryEmbedder, selectMemoryEmbeddingModelId, } from "./memory-embedding.js";
|
|
28
28
|
export { buildTerminalEvidenceEntry, appendTerminalEvidence, } from "./terminal-evidence.js";
|
|
29
|
-
export { handleFilesContent, listFilesDirectories, readFilesContent, readFilesPreview, readFilesTree, writeFilesContent, } from "./files.js";
|
|
29
|
+
export { handleFilesContent, handleFilesSearch, listFilesDirectories, readFilesContent, readFilesPreview, readFilesTree, searchFiles, writeFilesContent, } from "./files.js";
|
|
30
|
+
// PR4-W4 (ADR-0055) — additive exports so the deterministic context-quality gate
|
|
31
|
+
// (scripts/check-context-quality.mjs) can drive the REAL chat history-compaction splice end-to-end.
|
|
32
|
+
// Behavior-preserving: these names already exist on their modules; only the barrel surface widens.
|
|
33
|
+
export { conversationForGateway, MAX_CONTEXT_MESSAGES, } from "./chat-handlers.js";
|
|
34
|
+
export { conversationForGatewayWithCompaction, } from "./conversation-compaction.js";
|
|
30
35
|
// Epic #1307 / Issue #1314 — Prompt Enhancer governed surface. The BFF route handler and the reusable,
|
|
31
36
|
// deterministic orchestration the CLI command (`keiko prompt-enhancer`) drives so both surfaces produce
|
|
32
37
|
// byte-identical enhancements (AC1). Routed through the Model Gateway; never dispatches a model.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-knowledge-grounded-qa.d.ts","sourceRoot":"","sources":["../src/local-knowledge-grounded-qa.ts"],"names":[],"mappings":"AAGA,OAAO,EAQL,iBAAiB,EAEjB,KA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GAAG,SAAS,EACpC,YAAY,CAAC,EAAE,kCAAkC,EACjD,WAAW,CAAC,EAAE,aAAa,GAC1B,SAAS,8BAA8B,EAAE,CAe3C;AA2LD,wBAAsB,+BAA+B,CACnD,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,WAAW,CAAC,CA6CtB"}
|
|
@@ -614,7 +614,10 @@ function persistScopedGroundedAnswer(chat, input, deps, env, selected, result, s
|
|
|
614
614
|
const assistantContent = noEvidenceReason === undefined ? result.answer.trim() : LOCAL_KNOWLEDGE_NO_EVIDENCE_ANSWER;
|
|
615
615
|
const redactedUserContent = redactText(deps, input.content);
|
|
616
616
|
const redactedAssistantContent = redactText(deps, assistantContent);
|
|
617
|
-
|
|
617
|
+
const persisted = persistGroundedExchange(deps, chat.id, redactedUserContent, redactedAssistantContent);
|
|
618
|
+
const answer = buildLocalKnowledgeAnswer(chat, env.store, selected, persisted, result, elapsedMs, redactedAssistantContent, (value) => redactText(deps, value));
|
|
619
|
+
deps.store.attachGroundedAnswer(persisted[1].id, answer);
|
|
620
|
+
return answer;
|
|
618
621
|
}
|
|
619
622
|
async function runScopedGroundedAnswer(chat, input, deps, env, selected, signal) {
|
|
620
623
|
const embeddingAdapter = createEmbeddingAdapter(deps, selected.capsules);
|
|
@@ -647,9 +650,15 @@ export async function handleLocalKnowledgeGroundedAsk(chat, input, deps, signal)
|
|
|
647
650
|
const stateFailure = scopeStateFailure(selected);
|
|
648
651
|
if (stateFailure !== undefined) {
|
|
649
652
|
const redactedMessage = redactText(deps, stateFailure.message);
|
|
653
|
+
const persisted = persistGroundedExchange(deps, chat.id, redactText(deps, input.content), redactedMessage);
|
|
654
|
+
const answer = buildStateFailureAnswer(chat, selected, persisted, {
|
|
655
|
+
...stateFailure,
|
|
656
|
+
message: redactedMessage,
|
|
657
|
+
});
|
|
658
|
+
deps.store.attachGroundedAnswer(persisted[1].id, answer);
|
|
650
659
|
return {
|
|
651
660
|
status: 200,
|
|
652
|
-
body:
|
|
661
|
+
body: answer,
|
|
653
662
|
};
|
|
654
663
|
}
|
|
655
664
|
const answer = await runScopedGroundedAnswer(chat, input, deps, env, selected, signal);
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAmK/C,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACrE;AAID,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,SAAS,eAAsB,CAAC;AAC7C,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,OAAO,SAAS,CAAC;AAE5D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,eAAe,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAElD,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,CACzB,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,aAAa,KAChB,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAA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,EAAE,YAAY,CAAC;CAChC;AAUD,eAAO,MAAM,UAAU,EAAE,SAAS,eAAe,EAuYhD,CAAC;AA6BF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD;AAKD,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,UAAU,GAAG,oBAAoB,GAAG,SAAS,CA2B/C;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,CAEjE;AAED,wBAAgB,YAAY,IAAI,QAAQ,CAEvC;AAED,wBAAgB,oBAAoB,IAAI,QAAQ,CAE/C"}
|
package/dist/routes.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// (the SSE events route). Non-2xx bodies use the redacted error envelope `{ error: { code, message } }`.
|
|
7
7
|
import { SDK_VERSION } from "@oscharko-dev/keiko-sdk";
|
|
8
8
|
import { handleConfig, handleModels, handleWorkflows, handleWorkspace, handleEvidenceList, handleEvidenceDetail, } from "./read-handlers.js";
|
|
9
|
-
import { handleCreateRun,
|
|
9
|
+
import { handleCreateRun, handleRunEvents, handleCancelRun, handleGetRun, handleApplyRun, } from "./run-handlers.js";
|
|
10
10
|
import { handleListProjects, handleCreateProject, handleUpdateProject, handleDeleteProject, handleListChats, handleCreateChat, handleUpdateChat, handleDeleteChat, handleListMessages, handleCreateMessage, handleCreateRunSummaryPair, handleUpdateMessage, } from "./store-handlers.js";
|
|
11
11
|
import { handleCreateDesktopChat, handleSendDesktopChat } from "./chat-handlers.js";
|
|
12
12
|
import { handleSendDesktopChatStream } from "./chat-stream-handlers.js";
|
|
@@ -15,10 +15,10 @@ import { handleMemoryRetrieveContext, handleMemoryCaptureFromConversation, } fro
|
|
|
15
15
|
import { handleCancelConsolidationJob, handleCreateConsolidationJob, handleGetConsolidationJob, } from "./memory-consolidation-handlers.js";
|
|
16
16
|
import { handleRunMaintenance } from "./memory-maintenance-handlers.js";
|
|
17
17
|
import { handleGroundedAsk } from "./grounded-qa.js";
|
|
18
|
-
import {
|
|
18
|
+
import { handleGatewayReadiness } from "./gateway-readiness.js";
|
|
19
19
|
import { handleGatewaySetup } from "./gateway-setup.js";
|
|
20
20
|
import { handleCreateTerminalExecution, handleDeleteTerminalExecution, handleTerminalDirectories, handleTerminalEvents, handleTerminalPolicy, } from "./terminal-routes.js";
|
|
21
|
-
import { handleFilesContent, handleFilesDirectories, handleFilesPreview, handleFilesTree, } from "./files.js";
|
|
21
|
+
import { handleFilesContent, handleFilesDirectories, handleFilesPreview, handleFilesSearch, handleFilesTree, } from "./files.js";
|
|
22
22
|
import { handleEditorLanguage, handleEditorLanguageCapabilities } from "./editor/languageRoutes.js";
|
|
23
23
|
import { handleEditorContext, handleEditorLocalKnowledgeRetrieve, handleEditorRepoSearch, } from "./editor/contextRoutes.js";
|
|
24
24
|
import { handleEditorCompletion } from "./editor/completionRoutes.js";
|
|
@@ -45,6 +45,7 @@ export const API_ROUTES = [
|
|
|
45
45
|
{ method: "GET", pattern: "/api/health", handler: health },
|
|
46
46
|
{ method: "GET", pattern: "/api/config", handler: handleConfig },
|
|
47
47
|
{ method: "GET", pattern: "/api/models", handler: handleModels },
|
|
48
|
+
{ method: "POST", pattern: "/api/gateway/readiness", handler: handleGatewayReadiness },
|
|
48
49
|
{ method: "POST", pattern: "/api/gateway/setup", handler: handleGatewaySetup },
|
|
49
50
|
{ method: "GET", pattern: "/api/workflows", handler: handleWorkflows },
|
|
50
51
|
{ method: "POST", pattern: "/api/runs", handler: handleCreateRun },
|
|
@@ -62,8 +63,6 @@ export const API_ROUTES = [
|
|
|
62
63
|
{ method: "DELETE", pattern: "/api/projects", handler: handleDeleteProject },
|
|
63
64
|
{ method: "GET", pattern: "/api/chats", handler: handleListChats },
|
|
64
65
|
{ method: "POST", pattern: "/api/chats", handler: handleCreateChat },
|
|
65
|
-
// Issue #66 — composer launch path: persist chat pair and start the run as one BFF operation.
|
|
66
|
-
{ method: "POST", pattern: "/api/chats/runs", handler: handleCreateChatRun },
|
|
67
66
|
{ method: "PATCH", pattern: "/api/chats", handler: handleUpdateChat },
|
|
68
67
|
{ method: "DELETE", pattern: "/api/chats", handler: handleDeleteChat },
|
|
69
68
|
{ method: "GET", pattern: "/api/chats/messages", handler: handleListMessages },
|
|
@@ -78,11 +77,6 @@ export const API_ROUTES = [
|
|
|
78
77
|
{ method: "PATCH", pattern: "/api/chats/messages", handler: handleUpdateMessage },
|
|
79
78
|
// Issue #185 — grounded repository-aware Q&A. Composes #179-#183 behind the chat-scope binding.
|
|
80
79
|
{ method: "POST", pattern: "/api/chats/messages/grounded", handler: handleGroundedAsk },
|
|
81
|
-
{
|
|
82
|
-
method: "POST",
|
|
83
|
-
pattern: "/api/chats/messages/grounded/handoff",
|
|
84
|
-
handler: handleGroundedWorkflowHandoff,
|
|
85
|
-
},
|
|
86
80
|
// Desktop canvas V1 — real chat against the configured gateway model without new agent scope.
|
|
87
81
|
{ method: "POST", pattern: "/api/desktop/chats", handler: handleCreateDesktopChat },
|
|
88
82
|
{ method: "POST", pattern: "/api/desktop/chat", handler: handleSendDesktopChat },
|
|
@@ -101,6 +95,7 @@ export const API_ROUTES = [
|
|
|
101
95
|
// Desktop files — selected-root browser, preview, and editor control plane.
|
|
102
96
|
{ method: "GET", pattern: "/api/files/directories", handler: handleFilesDirectories },
|
|
103
97
|
{ method: "GET", pattern: "/api/files/tree", handler: handleFilesTree },
|
|
98
|
+
{ method: "GET", pattern: "/api/files/search", handler: handleFilesSearch },
|
|
104
99
|
{ method: "GET", pattern: "/api/files/preview", handler: handleFilesPreview },
|
|
105
100
|
{ method: "GET", pattern: "/api/files/content", handler: handleFilesContent },
|
|
106
101
|
{ method: "PATCH", pattern: "/api/files/content", handler: handleFilesContent },
|
package/dist/run-handlers.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RouteContext, RouteResult, HandlerOutcome } from "./routes.js";
|
|
2
2
|
import type { UiHandlerDeps } from "./deps.js";
|
|
3
3
|
export declare function handleCreateRun(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
|
|
4
|
-
export declare function handleCreateChatRun(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
|
|
5
4
|
export declare function handleRunEvents(ctx: RouteContext, deps: UiHandlerDeps): HandlerOutcome;
|
|
6
5
|
export declare function handleCancelRun(ctx: RouteContext, deps: UiHandlerDeps): RouteResult;
|
|
7
6
|
export declare function handleGetRun(ctx: RouteContext, deps: UiHandlerDeps): RouteResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-handlers.d.ts","sourceRoot":"","sources":["../src/run-handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-handlers.d.ts","sourceRoot":"","sources":["../src/run-handlers.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAoG/C,wBAAsB,eAAe,CACnC,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC,CAyCtB;AAeD,wBAAgB,eAAe,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,GAAG,cAAc,CAUtF;AA+BD,wBAAgB,eAAe,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,GAAG,WAAW,CAOnF;AAGD,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,GAAG,WAAW,CAYhF;AAuBD,wBAAsB,cAAc,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAwBjG"}
|
package/dist/run-handlers.js
CHANGED
|
@@ -5,17 +5,13 @@
|
|
|
5
5
|
// redacted final report projection (or status:"running"); apply is the ONLY write path, re-invoking
|
|
6
6
|
// the same workflow with apply:true through the existing gated path. No model is ever called
|
|
7
7
|
// directly; no guard is reimplemented; no secret reaches any response (live payloads are redacted).
|
|
8
|
-
import { randomUUID } from "node:crypto";
|
|
9
8
|
import { parseRunRequest } from "./run-request.js";
|
|
10
9
|
import { startRun, applyRun } from "./run-engine.js";
|
|
11
10
|
import { ActiveRunLimitError } from "./runs.js";
|
|
12
11
|
import { SSE_HEADERS, writeEvent, readyMessage } from "./sse.js";
|
|
13
12
|
import { errorBody, STREAMING } from "./routes.js";
|
|
14
13
|
import { currentRedactionSecrets } from "./deps.js";
|
|
15
|
-
import { createAuditRedactor } from "@oscharko-dev/keiko-evidence";
|
|
16
14
|
import { WorkspaceError } from "@oscharko-dev/keiko-workspace";
|
|
17
|
-
import { UiStoreError } from "./store/index.js";
|
|
18
|
-
import { memoryCaptureCustomerMatchers } from "./memory-capture-policy.js";
|
|
19
15
|
const MAX_BODY_BYTES = 1_000_000;
|
|
20
16
|
const VERIFY_NOOP_MODEL = {
|
|
21
17
|
call: () => Promise.reject(new Error("verify runs must not call the model")),
|
|
@@ -78,109 +74,6 @@ function resolveRunModel(parsed, deps) {
|
|
|
78
74
|
function isRecord(value) {
|
|
79
75
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80
76
|
}
|
|
81
|
-
function requireBodyString(body, name) {
|
|
82
|
-
const value = body[name];
|
|
83
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
84
|
-
return { status: 400, body: errorBody("BAD_REQUEST", `Field "${name}" is required.`) };
|
|
85
|
-
}
|
|
86
|
-
return value;
|
|
87
|
-
}
|
|
88
|
-
function requireBodyNumber(body, name) {
|
|
89
|
-
const value = body[name];
|
|
90
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
91
|
-
return {
|
|
92
|
-
status: 400,
|
|
93
|
-
body: errorBody("BAD_REQUEST", `Field "${name}" must be a finite number.`),
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
98
|
-
function requireBodyRecord(body, name) {
|
|
99
|
-
const value = body[name];
|
|
100
|
-
if (!isRecord(value)) {
|
|
101
|
-
return { status: 400, body: errorBody("BAD_REQUEST", `Field "${name}" must be an object.`) };
|
|
102
|
-
}
|
|
103
|
-
return value;
|
|
104
|
-
}
|
|
105
|
-
function parseJsonRecord(raw) {
|
|
106
|
-
let parsed;
|
|
107
|
-
try {
|
|
108
|
-
parsed = JSON.parse(raw);
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
return { status: 400, body: errorBody("BAD_REQUEST", "Request body is not valid JSON.") };
|
|
112
|
-
}
|
|
113
|
-
if (!isRecord(parsed)) {
|
|
114
|
-
return { status: 400, body: errorBody("BAD_REQUEST", "Request body must be a JSON object.") };
|
|
115
|
-
}
|
|
116
|
-
return parsed;
|
|
117
|
-
}
|
|
118
|
-
function isRouteResult(value) {
|
|
119
|
-
return isRecord(value) && typeof value.status === "number" && "body" in value;
|
|
120
|
-
}
|
|
121
|
-
function chatBelongsToProject(deps, projectPath, chatId) {
|
|
122
|
-
return deps.store.listChats(projectPath).some((chat) => chat.id === chatId);
|
|
123
|
-
}
|
|
124
|
-
function runSummaryDiscriminator(request) {
|
|
125
|
-
if (request.kind === "unit-tests") {
|
|
126
|
-
return { workflowId: "unit-test-generation", taskType: undefined };
|
|
127
|
-
}
|
|
128
|
-
if (request.kind === "bug-investigation") {
|
|
129
|
-
return { workflowId: "bug-investigation", taskType: undefined };
|
|
130
|
-
}
|
|
131
|
-
if (request.kind === "explain-plan") {
|
|
132
|
-
return { workflowId: undefined, taskType: "explain-plan" };
|
|
133
|
-
}
|
|
134
|
-
return { workflowId: undefined, taskType: "verify" };
|
|
135
|
-
}
|
|
136
|
-
function buildChatRunMessages(body, request, chatId, runId) {
|
|
137
|
-
const user = requireBodyRecord(body, "user");
|
|
138
|
-
if (isRouteResult(user))
|
|
139
|
-
return user;
|
|
140
|
-
const summary = requireBodyRecord(body, "summary");
|
|
141
|
-
if (isRouteResult(summary))
|
|
142
|
-
return summary;
|
|
143
|
-
const userContent = requireBodyString(user, "content");
|
|
144
|
-
if (typeof userContent !== "string")
|
|
145
|
-
return userContent;
|
|
146
|
-
const userTimestamp = requireBodyNumber(user, "timestamp");
|
|
147
|
-
if (typeof userTimestamp !== "number")
|
|
148
|
-
return userTimestamp;
|
|
149
|
-
const summaryContent = requireBodyString(summary, "content");
|
|
150
|
-
if (typeof summaryContent !== "string")
|
|
151
|
-
return summaryContent;
|
|
152
|
-
const summaryTimestamp = requireBodyNumber(summary, "timestamp");
|
|
153
|
-
if (typeof summaryTimestamp !== "number")
|
|
154
|
-
return summaryTimestamp;
|
|
155
|
-
const discriminator = runSummaryDiscriminator(request);
|
|
156
|
-
return [
|
|
157
|
-
{
|
|
158
|
-
chatId,
|
|
159
|
-
role: "user",
|
|
160
|
-
content: userContent,
|
|
161
|
-
timestamp: userTimestamp,
|
|
162
|
-
runId: undefined,
|
|
163
|
-
workflowId: undefined,
|
|
164
|
-
workflowStatus: undefined,
|
|
165
|
-
shortResult: undefined,
|
|
166
|
-
taskType: undefined,
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
chatId,
|
|
170
|
-
role: "system",
|
|
171
|
-
content: summaryContent,
|
|
172
|
-
timestamp: summaryTimestamp,
|
|
173
|
-
runId,
|
|
174
|
-
workflowId: discriminator.workflowId,
|
|
175
|
-
workflowStatus: "running",
|
|
176
|
-
shortResult: undefined,
|
|
177
|
-
taskType: discriminator.taskType,
|
|
178
|
-
},
|
|
179
|
-
];
|
|
180
|
-
}
|
|
181
|
-
function storeErrorResult(error) {
|
|
182
|
-
return { status: error.status, body: errorBody(error.code, error.message) };
|
|
183
|
-
}
|
|
184
77
|
// Static, path-safe message for workspace errors surfaced during run launch. The underlying
|
|
185
78
|
// WorkspaceError messages may carry absolute paths — we never echo them (ADR-0005, CWE-209).
|
|
186
79
|
const WORKSPACE_RUN_ERROR_MESSAGE = "The selected workspace could not be prepared: no recognized project workspace marker was found, or the target file could not be read.";
|
|
@@ -190,86 +83,6 @@ function workspaceRunErrorResult() {
|
|
|
190
83
|
body: errorBody("WORKSPACE_UNAVAILABLE", WORKSPACE_RUN_ERROR_MESSAGE),
|
|
191
84
|
};
|
|
192
85
|
}
|
|
193
|
-
function markSummaryFailed(deps, message, shortResult) {
|
|
194
|
-
try {
|
|
195
|
-
deps.store.updateMessage(message.id, { workflowStatus: "failed", shortResult });
|
|
196
|
-
}
|
|
197
|
-
catch {
|
|
198
|
-
// Best-effort compensation only. The original start error remains the response source.
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function parseChatRunEnvelope(raw, deps) {
|
|
202
|
-
const body = parseJsonRecord(raw);
|
|
203
|
-
if (isRouteResult(body))
|
|
204
|
-
return body;
|
|
205
|
-
const chatId = requireBodyString(body, "chatId");
|
|
206
|
-
if (isRouteResult(chatId))
|
|
207
|
-
return chatId;
|
|
208
|
-
const projectPath = requireBodyString(body, "projectPath");
|
|
209
|
-
if (isRouteResult(projectPath))
|
|
210
|
-
return projectPath;
|
|
211
|
-
if (!chatBelongsToProject(deps, projectPath, chatId)) {
|
|
212
|
-
return { status: 404, body: errorBody("NOT_FOUND", "Chat not found.") };
|
|
213
|
-
}
|
|
214
|
-
const runBody = requireBodyRecord(body, "run");
|
|
215
|
-
if (isRouteResult(runBody))
|
|
216
|
-
return runBody;
|
|
217
|
-
return { body, chatId, projectPath, runBody };
|
|
218
|
-
}
|
|
219
|
-
function validateChatRunRequest(runBody, deps) {
|
|
220
|
-
const parsed = parseRunRequest(JSON.stringify(runBody));
|
|
221
|
-
if ("code" in parsed) {
|
|
222
|
-
return { status: 400, body: errorBody(parsed.code, parsed.message) };
|
|
223
|
-
}
|
|
224
|
-
const unregistered = rejectUnregisteredWorkspace(parsed, deps);
|
|
225
|
-
if (unregistered !== null)
|
|
226
|
-
return unregistered;
|
|
227
|
-
const model = resolveRunModel(parsed, deps);
|
|
228
|
-
return model === undefined
|
|
229
|
-
? { status: 400, body: errorBody("NO_MODEL", "No model provider is configured.") }
|
|
230
|
-
: { request: parsed, model };
|
|
231
|
-
}
|
|
232
|
-
function engineContextFor(deps, request, model) {
|
|
233
|
-
return {
|
|
234
|
-
request,
|
|
235
|
-
model,
|
|
236
|
-
registry: deps.registry,
|
|
237
|
-
evidence: {
|
|
238
|
-
store: deps.evidenceStore,
|
|
239
|
-
env: deps.env,
|
|
240
|
-
additionalSecrets: currentRedactionSecrets(deps),
|
|
241
|
-
},
|
|
242
|
-
memoryVault: deps.memoryVault,
|
|
243
|
-
memoryAuditRedactString: createAuditRedactor({ additionalSecrets: currentRedactionSecrets(deps) }, deps.env),
|
|
244
|
-
memoryCustomerIdentifierMatchers: memoryCaptureCustomerMatchers(deps),
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
function persistChatRunMessages(deps, envelope, request, runId) {
|
|
248
|
-
const messagesInput = buildChatRunMessages(envelope.body, request, envelope.chatId, runId);
|
|
249
|
-
if (isRouteResult(messagesInput))
|
|
250
|
-
return messagesInput;
|
|
251
|
-
try {
|
|
252
|
-
return deps.store.createMessages(messagesInput);
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
if (error instanceof UiStoreError)
|
|
256
|
-
return storeErrorResult(error);
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function startPersistedChatRun(deps, request, model, runId, messages) {
|
|
261
|
-
try {
|
|
262
|
-
const run = startRun(engineContextFor(deps, request, model), deps.redactor, { runId });
|
|
263
|
-
return { status: 202, body: { run, messages } };
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
const summary = messages[1];
|
|
267
|
-
if (summary !== undefined) {
|
|
268
|
-
markSummaryFailed(deps, summary, "Run could not be started.");
|
|
269
|
-
}
|
|
270
|
-
return mapRunStartError(error);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
86
|
function mapRunStartError(error) {
|
|
274
87
|
if (error instanceof ActiveRunLimitError) {
|
|
275
88
|
return { status: 429, body: errorBody("TOO_MANY_RUNS", "The active run limit is reached.") };
|
|
@@ -324,36 +137,6 @@ export async function handleCreateRun(ctx, deps) {
|
|
|
324
137
|
return mapRunStartError(error);
|
|
325
138
|
}
|
|
326
139
|
}
|
|
327
|
-
// Route — POST /api/chats/runs. Composer-specific path that makes Issue #66's chat invariant
|
|
328
|
-
// explicit: a successful workflow launch first reserves a runId and persists exactly one user
|
|
329
|
-
// message plus one system run summary, then starts the run with that reserved runId. If persistence
|
|
330
|
-
// fails, no run is started; if the start is refused, the summary is terminalized as failed.
|
|
331
|
-
export async function handleCreateChatRun(ctx, deps) {
|
|
332
|
-
let raw;
|
|
333
|
-
try {
|
|
334
|
-
raw = await readBody(ctx.req);
|
|
335
|
-
}
|
|
336
|
-
catch (error) {
|
|
337
|
-
if (error instanceof BodyTooLargeError) {
|
|
338
|
-
return {
|
|
339
|
-
status: 413,
|
|
340
|
-
body: errorBody("PAYLOAD_TOO_LARGE", "Request body exceeds the size limit."),
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
throw error;
|
|
344
|
-
}
|
|
345
|
-
const envelope = parseChatRunEnvelope(raw, deps);
|
|
346
|
-
if (isRouteResult(envelope))
|
|
347
|
-
return envelope;
|
|
348
|
-
const validated = validateChatRunRequest(envelope.runBody, deps);
|
|
349
|
-
if (isRouteResult(validated))
|
|
350
|
-
return validated;
|
|
351
|
-
const runId = randomUUID();
|
|
352
|
-
const messages = persistChatRunMessages(deps, envelope, validated.request, runId);
|
|
353
|
-
if (isRouteResult(messages))
|
|
354
|
-
return messages;
|
|
355
|
-
return startPersistedChatRun(deps, validated.request, validated.model, runId, messages);
|
|
356
|
-
}
|
|
357
140
|
function lastEventId(req) {
|
|
358
141
|
const header = req.headers["last-event-id"];
|
|
359
142
|
const value = Array.isArray(header) ? header[0] : header;
|
package/dist/store/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/store/db.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,KAAK,EAMV,OAAO,EACP,qBAAqB,EAKtB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/store/db.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,KAAK,EAMV,OAAO,EACP,qBAAqB,EAKtB,MAAM,YAAY,CAAC;AAkCpB,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAM9E;AAiKD,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAa3C,wBAAgB,qBAAqB,CAAC,IAAI,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAI3E;AAgCD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAkB/D;AAED,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAEhG;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAEvF"}
|
package/dist/store/db.js
CHANGED
|
@@ -8,7 +8,7 @@ import { randomUUID } from "node:crypto";
|
|
|
8
8
|
import { runMigrations } from "./schema.js";
|
|
9
9
|
import { deleteProject as sqlDeleteProject, getProject as sqlGetProject, listProjects as sqlListProjects, updateProject as sqlUpdateProject, upsertProject as sqlUpsertProject, } from "./projects.js";
|
|
10
10
|
import { deleteChat as sqlDeleteChat, findChatById as sqlFindChatById, insertChat as sqlInsertChat, listChats as sqlListChats, listChatsLimited as sqlListChatsLimited, touchChat as sqlTouchChat, updateChat as sqlUpdateChat, } from "./chats.js";
|
|
11
|
-
import { findMessageById as sqlFindMessageById, insertMessage as sqlInsertMessage, listMessages as sqlListMessages, listMessagesLimited as sqlListMessagesLimited, updateMessage as sqlUpdateMessage, } from "./messages.js";
|
|
11
|
+
import { findMessageById as sqlFindMessageById, attachGroundedAnswer as sqlAttachGroundedAnswer, insertMessage as sqlInsertMessage, listMessages as sqlListMessages, listMessagesLimited as sqlListMessagesLimited, updateMessage as sqlUpdateMessage, } from "./messages.js";
|
|
12
12
|
import { validateProjectPath } from "./validation.js";
|
|
13
13
|
import { basename } from "node:path";
|
|
14
14
|
import { invalidRequest } from "./errors.js";
|
|
@@ -111,6 +111,7 @@ function buildStore(db, options) {
|
|
|
111
111
|
},
|
|
112
112
|
createMessages: (messages) => createMessageBatch(db, options, messages),
|
|
113
113
|
updateMessage: (id, patch) => sqlUpdateMessage(db, id, patch, options.redactString),
|
|
114
|
+
attachGroundedAnswer: (id, answer) => sqlAttachGroundedAnswer(db, id, answer, options.redactString),
|
|
114
115
|
close: () => {
|
|
115
116
|
db.close();
|
|
116
117
|
},
|
package/dist/store/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { Chat, ChatConnectedScope, ChatLocalKnowledgeScope, ChatMessage, ChatRole, CreateChatOptions, NewChatMessage, Project, UiStore, UiStoreFactoryOptions, UpdateChatOptions, UpdateChatMessagePatch, UpdateChatPatch, UpdateProjectPatch, WorkflowStatus, } from "./types.js";
|
|
1
|
+
export type { Chat, ChatConnectedScope, ChatLocalKnowledgeScope, ChatMessage, ChatRole, CreateChatOptions, GroundedAnswer, NewChatMessage, Project, UiStore, UiStoreFactoryOptions, UpdateChatOptions, UpdateChatMessagePatch, UpdateChatPatch, UpdateProjectPatch, WorkflowStatus, } from "./types.js";
|
|
2
2
|
export { UiStoreError, type UiStoreErrorCode, invalidPath, invalidRequest, notFound, pathNotDirectory, pathNotFound, projectExists, } from "./errors.js";
|
|
3
3
|
export { classifyPathShape, validateProjectPath, type PathShape, type ValidateProjectPathOptions, } from "./validation.js";
|
|
4
4
|
export { assertUiDbOutsideProject, resolveUiDbPath, UI_DB_FILENAME, UI_DB_DIRNAME, } from "./paths.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,IAAI,EACJ,kBAAkB,EAClB,uBAAuB,EACvB,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,OAAO,EACP,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,YAAY,EACZ,KAAK,gBAAgB,EACrB,WAAW,EACX,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,0BAA0B,GAChC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,IAAI,EACJ,kBAAkB,EAClB,uBAAuB,EACvB,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,OAAO,EACP,OAAO,EACP,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,YAAY,EACZ,KAAK,gBAAgB,EACrB,WAAW,EACX,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,0BAA0B,GAChC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}
|
package/dist/store/messages.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { DatabaseSync } from "node:sqlite";
|
|
2
|
-
import type { ChatMessage, NewChatMessage, UpdateChatMessagePatch } from "./types.js";
|
|
2
|
+
import type { ChatMessage, GroundedAnswer, NewChatMessage, UpdateChatMessagePatch } from "./types.js";
|
|
3
3
|
export declare function listMessages(db: DatabaseSync, chatId: string): readonly ChatMessage[];
|
|
4
4
|
export declare function listMessagesLimited(db: DatabaseSync, chatId: string, limit: number): readonly ChatMessage[];
|
|
5
5
|
export declare function findMessageById(db: DatabaseSync, id: string): ChatMessage | undefined;
|
|
6
6
|
export declare function insertMessage(db: DatabaseSync, id: string, msg: NewChatMessage, redactString: (s: string) => string): ChatMessage;
|
|
7
|
+
export declare function attachGroundedAnswer(db: DatabaseSync, id: string, answer: GroundedAnswer, redactString: (s: string) => string): ChatMessage;
|
|
7
8
|
export declare function updateMessage(db: DatabaseSync, id: string, patch: UpdateChatMessagePatch, redactString: (s: string) => string): ChatMessage;
|
|
8
9
|
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/store/messages.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EACV,WAAW,EAEX,cAAc,EACd,sBAAsB,EAEvB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/store/messages.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EACV,WAAW,EAEX,cAAc,EACd,cAAc,EACd,sBAAsB,EAEvB,MAAM,YAAY,CAAC;AA4IpB,wBAAgB,YAAY,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,WAAW,EAAE,CAErF;AAED,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,YAAY,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,SAAS,WAAW,EAAE,CAOxB;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAGrF;AAED,wBAAgB,aAAa,CAC3B,EAAE,EAAE,YAAY,EAChB,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAClC,WAAW,CAsBb;AAED,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,YAAY,EAChB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAClC,WAAW,CAcb;AAOD,wBAAgB,aAAa,CAC3B,EAAE,EAAE,YAAY,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,sBAAsB,EAC7B,YAAY,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAClC,WAAW,CA6Bb"}
|