@tachu/host-defaults 1.0.0-rc.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/CHANGELOG.md +52 -0
- package/LICENSE +201 -0
- package/README.md +200 -0
- package/README_ZH.md +201 -0
- package/dist/build-host-engine-dependencies.d.ts +51 -0
- package/dist/build-host-engine-dependencies.d.ts.map +1 -0
- package/dist/build-host-engine-dependencies.js +70 -0
- package/dist/build-host-engine-dependencies.js.map +1 -0
- package/dist/capabilities.d.ts +10 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +26 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/providers.d.ts +10 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +104 -0
- package/dist/providers.js.map +1 -0
- package/dist/resolve-embedding-runtime.d.ts +11 -0
- package/dist/resolve-embedding-runtime.d.ts.map +1 -0
- package/dist/resolve-embedding-runtime.js +26 -0
- package/dist/resolve-embedding-runtime.js.map +1 -0
- package/dist/resolve-projection-stack.d.ts +59 -0
- package/dist/resolve-projection-stack.d.ts.map +1 -0
- package/dist/resolve-projection-stack.js +146 -0
- package/dist/resolve-projection-stack.js.map +1 -0
- package/dist/resolve-semantic-judge.d.ts +3 -0
- package/dist/resolve-semantic-judge.d.ts.map +1 -0
- package/dist/resolve-semantic-judge.js +18 -0
- package/dist/resolve-semantic-judge.js.map +1 -0
- package/dist/semantic-retrieval.d.ts +9 -0
- package/dist/semantic-retrieval.d.ts.map +1 -0
- package/dist/semantic-retrieval.js +44 -0
- package/dist/semantic-retrieval.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type AdapterCallContext, type EmbeddingRuntime, type EngineConfig, type ObservabilityEmitter, type ProviderAdapter, type VectorIndexAdapter } from "@tachu/core";
|
|
2
|
+
import { projectMemoryRefs, type ProjectionProjectorDeps } from "@tachu/extensions/memory";
|
|
3
|
+
export interface ResolveProjectionStackOptions {
|
|
4
|
+
/** When true, missing embedding runtime or vector index fails closed. */
|
|
5
|
+
required?: boolean | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Explicit override. When provided, host-side adapter selection is skipped
|
|
8
|
+
* and this adapter is used verbatim. Useful for tests and custom hosts that
|
|
9
|
+
* want to drive a synthetic in-memory adapter.
|
|
10
|
+
*/
|
|
11
|
+
vectorIndex?: VectorIndexAdapter | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Working directory for relative paths in adapter construction (e.g. the
|
|
14
|
+
* LocalFs index defaults to `<cwd>/.tachu/vector-index.json`).
|
|
15
|
+
*/
|
|
16
|
+
cwd?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface ProjectionStack {
|
|
19
|
+
embeddingRuntime: EmbeddingRuntime;
|
|
20
|
+
vectorIndex: VectorIndexAdapter;
|
|
21
|
+
/** Identifier of the concrete adapter wired (`qdrant`, `local-fs`, or `injected`). */
|
|
22
|
+
adapterKind: "qdrant" | "local-fs" | "injected";
|
|
23
|
+
bindProjectionProject: (loadEntry: ProjectionProjectorDeps["loadEntry"], ctx: AdapterCallContext) => (sessionId: string, refs: readonly string[], signal: AbortSignal) => ReturnType<typeof projectMemoryRefs>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Select / construct a {@link VectorIndexAdapter} from config + options.
|
|
27
|
+
*
|
|
28
|
+
* Resolution order (first match wins):
|
|
29
|
+
*
|
|
30
|
+
* 1. `options.vectorIndex` — explicit injection (tests / custom hosts).
|
|
31
|
+
* 2. `config.providers?.qdrant.extra.vectorIndex` — Qdrant connection details
|
|
32
|
+
* (`url`, `apiKey`, `collectionName`, `vectorSize`). When present a
|
|
33
|
+
* {@link QdrantVectorIndexAdapter} is constructed.
|
|
34
|
+
* 3. Default: a {@link LocalFsVectorIndexAdapter} persisting to
|
|
35
|
+
* `<cwd>/.tachu/vector-index.json`.
|
|
36
|
+
*
|
|
37
|
+
* The returned adapter is always pure-vector: it never accepts string `upsert`
|
|
38
|
+
* shortcuts, in line with + /.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveVectorIndexAdapter(config: EngineConfig, options?: {
|
|
41
|
+
cwd?: string | undefined;
|
|
42
|
+
vectorIndex?: VectorIndexAdapter | undefined;
|
|
43
|
+
}): {
|
|
44
|
+
adapter: VectorIndexAdapter;
|
|
45
|
+
kind: "qdrant" | "local-fs" | "injected";
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Wire embed + vector index for memory projection ( / / ).
|
|
49
|
+
*
|
|
50
|
+
* The returned {@link ProjectionStack} is plug-and-play for hosts: pass
|
|
51
|
+
* `vectorIndex` and `bindProjectionProject(loadEntry, ctx)` to
|
|
52
|
+
* {@link FsMemorySystem} alongside a {@link ProjectionOutbox}, and the
|
|
53
|
+
* {@link ProjectionWorker} produced by `createProjectionWorker()` will index
|
|
54
|
+
* memory entries through the host-resolved {@link EmbeddingRuntime} +
|
|
55
|
+
* {@link VectorIndexAdapter} stack — never through the retired
|
|
56
|
+
* `InMemoryMemorySystem.project()` text-embed shortcut.
|
|
57
|
+
*/
|
|
58
|
+
export declare function resolveProjectionStack(config: EngineConfig, providers: readonly ProviderAdapter[], observability: ObservabilityEmitter, options?: ResolveProjectionStackOptions): ProjectionStack | undefined;
|
|
59
|
+
//# sourceMappingURL=resolve-projection-stack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-projection-stack.d.ts","sourceRoot":"","sources":["../src/resolve-projection-stack.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,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,CAsF7B"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { isAbsolute, join } from "node:path";
|
|
2
|
+
import { projectMemoryRefs } from "@tachu/extensions/memory";
|
|
3
|
+
import { LocalFsVectorIndexAdapter, QdrantVectorIndexAdapter } from "@tachu/extensions/vector";
|
|
4
|
+
import { assertCapabilityProvided } from "./capabilities";
|
|
5
|
+
import { ENGINE_INIT_CORRELATION } from "./constants";
|
|
6
|
+
import { resolveEmbeddingRuntime } from "./resolve-embedding-runtime";
|
|
7
|
+
/**
|
|
8
|
+
* Select / construct a {@link VectorIndexAdapter} from config + options.
|
|
9
|
+
*
|
|
10
|
+
* Resolution order (first match wins):
|
|
11
|
+
*
|
|
12
|
+
* 1. `options.vectorIndex` — explicit injection (tests / custom hosts).
|
|
13
|
+
* 2. `config.providers?.qdrant.extra.vectorIndex` — Qdrant connection details
|
|
14
|
+
* (`url`, `apiKey`, `collectionName`, `vectorSize`). When present a
|
|
15
|
+
* {@link QdrantVectorIndexAdapter} is constructed.
|
|
16
|
+
* 3. Default: a {@link LocalFsVectorIndexAdapter} persisting to
|
|
17
|
+
* `<cwd>/.tachu/vector-index.json`.
|
|
18
|
+
*
|
|
19
|
+
* The returned adapter is always pure-vector: it never accepts string `upsert`
|
|
20
|
+
* shortcuts, in line with + /.
|
|
21
|
+
*/
|
|
22
|
+
export function resolveVectorIndexAdapter(config, options = {}) {
|
|
23
|
+
if (options.vectorIndex !== undefined) {
|
|
24
|
+
return { adapter: options.vectorIndex, kind: "injected" };
|
|
25
|
+
}
|
|
26
|
+
const qdrant = readQdrantConfig(config);
|
|
27
|
+
if (qdrant !== undefined) {
|
|
28
|
+
return {
|
|
29
|
+
adapter: new QdrantVectorIndexAdapter({
|
|
30
|
+
url: qdrant.url,
|
|
31
|
+
...(qdrant.apiKey !== undefined ? { apiKey: qdrant.apiKey } : {}),
|
|
32
|
+
collectionName: qdrant.collectionName,
|
|
33
|
+
vectorSize: qdrant.vectorSize,
|
|
34
|
+
}),
|
|
35
|
+
kind: "qdrant",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const cwd = options.cwd ?? process.cwd();
|
|
39
|
+
const filePath = isAbsolute(".tachu/vector-index.json")
|
|
40
|
+
? ".tachu/vector-index.json"
|
|
41
|
+
: join(cwd, ".tachu", "vector-index.json");
|
|
42
|
+
return {
|
|
43
|
+
adapter: new LocalFsVectorIndexAdapter({ filePath }),
|
|
44
|
+
kind: "local-fs",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function readQdrantConfig(config) {
|
|
48
|
+
const providers = config.providers;
|
|
49
|
+
const qdrant = providers?.qdrant;
|
|
50
|
+
if (!qdrant)
|
|
51
|
+
return undefined;
|
|
52
|
+
const extra = (qdrant.extra ?? {});
|
|
53
|
+
const vi = extra.vectorIndex ?? {};
|
|
54
|
+
const url = vi.url ?? qdrant.baseURL;
|
|
55
|
+
const collectionName = vi.collectionName ?? "tachu-memory";
|
|
56
|
+
const vectorSize = typeof vi.vectorSize === "number" ? vi.vectorSize : undefined;
|
|
57
|
+
if (typeof url !== "string" || url.length === 0)
|
|
58
|
+
return undefined;
|
|
59
|
+
if (typeof vectorSize !== "number" || vectorSize <= 0)
|
|
60
|
+
return undefined;
|
|
61
|
+
return {
|
|
62
|
+
url,
|
|
63
|
+
apiKey: vi.apiKey ?? qdrant.apiKey,
|
|
64
|
+
collectionName,
|
|
65
|
+
vectorSize,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Wire embed + vector index for memory projection ( / / ).
|
|
70
|
+
*
|
|
71
|
+
* The returned {@link ProjectionStack} is plug-and-play for hosts: pass
|
|
72
|
+
* `vectorIndex` and `bindProjectionProject(loadEntry, ctx)` to
|
|
73
|
+
* {@link FsMemorySystem} alongside a {@link ProjectionOutbox}, and the
|
|
74
|
+
* {@link ProjectionWorker} produced by `createProjectionWorker()` will index
|
|
75
|
+
* memory entries through the host-resolved {@link EmbeddingRuntime} +
|
|
76
|
+
* {@link VectorIndexAdapter} stack — never through the retired
|
|
77
|
+
* `InMemoryMemorySystem.project()` text-embed shortcut.
|
|
78
|
+
*/
|
|
79
|
+
export function resolveProjectionStack(config, providers, observability, options = {}) {
|
|
80
|
+
const resolved = resolveEmbeddingRuntime(config, providers);
|
|
81
|
+
const { adapter: vectorIndex, kind: adapterKind } = (() => {
|
|
82
|
+
try {
|
|
83
|
+
return resolveVectorIndexAdapter(config, {
|
|
84
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
85
|
+
...(options.vectorIndex !== undefined ? { vectorIndex: options.vectorIndex } : {}),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
observability.emit({
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
correlation: ENGINE_INIT_CORRELATION,
|
|
92
|
+
phase: "init",
|
|
93
|
+
type: "warning",
|
|
94
|
+
payload: {
|
|
95
|
+
status: "projection.vector-index.error",
|
|
96
|
+
message: error instanceof Error ? error.message : String(error),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
return { adapter: undefined, kind: "local-fs" };
|
|
100
|
+
}
|
|
101
|
+
})();
|
|
102
|
+
if (options.required === true) {
|
|
103
|
+
assertCapabilityProvided(observability, "embedding-runtime", resolved !== undefined, "embedding runtime required for memory projection");
|
|
104
|
+
assertCapabilityProvided(observability, "vector-index", vectorIndex !== undefined, "vector index required for memory projection");
|
|
105
|
+
}
|
|
106
|
+
if (!resolved || !vectorIndex) {
|
|
107
|
+
if (options.required !== true) {
|
|
108
|
+
observability.emit({
|
|
109
|
+
timestamp: Date.now(),
|
|
110
|
+
correlation: ENGINE_INIT_CORRELATION,
|
|
111
|
+
phase: "init",
|
|
112
|
+
type: "warning",
|
|
113
|
+
payload: {
|
|
114
|
+
status: "projection.disabled",
|
|
115
|
+
reason: !resolved
|
|
116
|
+
? "no embedding runtime available"
|
|
117
|
+
: "no vector index adapter configured",
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
observability.emit({
|
|
124
|
+
timestamp: Date.now(),
|
|
125
|
+
correlation: ENGINE_INIT_CORRELATION,
|
|
126
|
+
phase: "init",
|
|
127
|
+
type: "progress",
|
|
128
|
+
payload: {
|
|
129
|
+
status: "projection.available",
|
|
130
|
+
providerId: resolved.provider.id,
|
|
131
|
+
model: resolved.model,
|
|
132
|
+
vectorIndexKind: adapterKind,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
embeddingRuntime: resolved.runtime,
|
|
137
|
+
vectorIndex,
|
|
138
|
+
adapterKind,
|
|
139
|
+
bindProjectionProject: (loadEntry, ctx) => (sessionId, refs, signal) => projectMemoryRefs({
|
|
140
|
+
embedding: resolved.runtime,
|
|
141
|
+
vectorIndex,
|
|
142
|
+
loadEntry,
|
|
143
|
+
}, sessionId, refs, ctx, signal),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=resolve-projection-stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-projection-stack.js","sourceRoot":"","sources":["../src/resolve-projection-stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAS7C,OAAO,EAAE,iBAAiB,EAAgC,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAwCtE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAoB,EACpB,UAAsF,EAAE;IAExF,IAAI,OAAO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S,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,WAAW,EAAE,uBAAuB;QACpC,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP,MAAM,EAAE,sBAAsB;YAC9B,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE;YAChC,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,eAAe,EAAE,WAAW;SAC7B;KACF,CAAC,CAAC;IAEH,OAAO;QACL,gBAAgB,EAAE,QAAQ,CAAC,OAAO;QAClC,WAAW;QACX,WAAW;QACX,qBAAqB,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CACrE,iBAAiB,CACf;YACE,SAAS,EAAE,QAAQ,CAAC,OAAO;YAC3B,WAAW;YACX,SAAS;SACV,EACD,SAAS,EACT,IAAI,EACJ,GAAG,EACH,MAAM,CACP;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type EngineConfig, type ProviderAdapter, type SemanticJudgeAdapter } from "@tachu/core";
|
|
2
|
+
export declare function resolveSemanticJudge(config: EngineConfig, providers: readonly ProviderAdapter[]): SemanticJudgeAdapter | undefined;
|
|
3
|
+
//# sourceMappingURL=resolve-semantic-judge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-semantic-judge.d.ts","sourceRoot":"","sources":["../src/resolve-semantic-judge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAErB,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,SAAS,eAAe,EAAE,GACpC,oBAAoB,GAAG,SAAS,CAiBlC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ProviderSemanticJudgeAdapter, } from "@tachu/core";
|
|
2
|
+
export function resolveSemanticJudge(config, providers) {
|
|
3
|
+
const validationMapping = config.models.capabilityMapping.validation;
|
|
4
|
+
const preferredId = validationMapping?.provider;
|
|
5
|
+
const provider = (preferredId ? providers.find((item) => item.id === preferredId) : undefined) ??
|
|
6
|
+
providers.find((item) => typeof item.chat === "function");
|
|
7
|
+
if (!provider)
|
|
8
|
+
return undefined;
|
|
9
|
+
const model = validationMapping?.model ?? "validation-default";
|
|
10
|
+
return new ProviderSemanticJudgeAdapter({
|
|
11
|
+
provider,
|
|
12
|
+
model,
|
|
13
|
+
...(config.validation?.semanticJudgeSystemPromptBase
|
|
14
|
+
? { systemPromptBase: config.validation.semanticJudgeSystemPromptBase }
|
|
15
|
+
: {}),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=resolve-semantic-judge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-semantic-judge.js","sourceRoot":"","sources":["../src/resolve-semantic-judge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,GAI7B,MAAM,aAAa,CAAC;AAErB,MAAM,UAAU,oBAAoB,CAClC,MAAoB,EACpB,SAAqC;IAErC,MAAM,iBAAiB,GACrB,MAAM,CAAC,MAAM,CAAC,iBACf,CAAC,UAAU,CAAC;IACb,MAAM,WAAW,GAAG,iBAAiB,EAAE,QAAQ,CAAC;IAChD,MAAM,QAAQ,GACZ,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7E,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;IAC5D,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,MAAM,KAAK,GAAG,iBAAiB,EAAE,KAAK,IAAI,oBAAoB,CAAC;IAC/D,OAAO,IAAI,4BAA4B,CAAC;QACtC,QAAQ;QACR,KAAK;QACL,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,6BAA6B;YAClD,CAAC,CAAC,EAAE,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,6BAA6B,EAAE;YACvE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type EngineConfig, type ObservabilityEmitter, type ProviderAdapter, type SemanticRetrievalFacade } from "@tachu/core";
|
|
2
|
+
export interface ResolveSemanticRetrievalFacadeResult {
|
|
3
|
+
facade: SemanticRetrievalFacade;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 装配 SemanticRetrievalFacade 并 emit 标准 init 事件。
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveSemanticRetrievalFacade(config: EngineConfig, providers: readonly ProviderAdapter[], observability: ObservabilityEmitter): ResolveSemanticRetrievalFacadeResult;
|
|
9
|
+
//# sourceMappingURL=semantic-retrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-retrieval.d.ts","sourceRoot":"","sources":["../src/semantic-retrieval.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC7B,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,oCAAoC;IACnD,MAAM,EAAE,uBAAuB,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,SAAS,eAAe,EAAE,EACrC,aAAa,EAAE,oBAAoB,GAClC,oCAAoC,CAwCtC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DefaultRetrievalPolicyRegistry, DefaultSemanticRetrievalFacade, } from "@tachu/core";
|
|
2
|
+
import { ENGINE_INIT_CORRELATION } from "./constants";
|
|
3
|
+
import { resolveEmbeddingRuntime } from "./resolve-embedding-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* 装配 SemanticRetrievalFacade 并 emit 标准 init 事件。
|
|
6
|
+
*/
|
|
7
|
+
export function resolveSemanticRetrievalFacade(config, providers, observability) {
|
|
8
|
+
const resolved = resolveEmbeddingRuntime(config, providers);
|
|
9
|
+
if (resolved) {
|
|
10
|
+
const facade = new DefaultSemanticRetrievalFacade({
|
|
11
|
+
policy: new DefaultRetrievalPolicyRegistry(),
|
|
12
|
+
embedding: resolved.runtime,
|
|
13
|
+
});
|
|
14
|
+
observability.emit({
|
|
15
|
+
timestamp: Date.now(),
|
|
16
|
+
correlation: ENGINE_INIT_CORRELATION,
|
|
17
|
+
phase: "semantic-retrieval",
|
|
18
|
+
type: "progress",
|
|
19
|
+
payload: {
|
|
20
|
+
status: "available",
|
|
21
|
+
providerId: resolved.provider.id,
|
|
22
|
+
model: resolved.model,
|
|
23
|
+
strategy: "embedding_runtime",
|
|
24
|
+
reason: "provider exposes embed(); host wired DefaultSemanticRetrievalFacade with ProviderEmbeddingRuntimeAdapter",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return { facade };
|
|
28
|
+
}
|
|
29
|
+
const facade = new DefaultSemanticRetrievalFacade({
|
|
30
|
+
policy: new DefaultRetrievalPolicyRegistry(),
|
|
31
|
+
});
|
|
32
|
+
observability.emit({
|
|
33
|
+
timestamp: Date.now(),
|
|
34
|
+
correlation: ENGINE_INIT_CORRELATION,
|
|
35
|
+
phase: "semantic-retrieval",
|
|
36
|
+
type: "warning",
|
|
37
|
+
payload: {
|
|
38
|
+
status: "disabled",
|
|
39
|
+
reason: "no registered provider implements embed(); semantic retrieval falls back to local_scan or bypass per RetrievalPolicy",
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
return { facade };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=semantic-retrieval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-retrieval.js","sourceRoot":"","sources":["../src/semantic-retrieval.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,GAK/B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAMtE;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAAoB,EACpB,SAAqC,EACrC,aAAmC;IAEnC,MAAM,QAAQ,GAAG,uBAAuB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE5D,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,IAAI,8BAA8B,CAAC;YAChD,MAAM,EAAE,IAAI,8BAA8B,EAAE;YAC5C,SAAS,EAAE,QAAQ,CAAC,OAAO;SAC5B,CAAC,CAAC;QACH,aAAa,CAAC,IAAI,CAAC;YACjB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,WAAW,EAAE,uBAAuB;YACpC,KAAK,EAAE,oBAAoB;YAC3B,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE;gBACP,MAAM,EAAE,WAAW;gBACnB,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE;gBAChC,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,QAAQ,EAAE,mBAAmB;gBAC7B,MAAM,EACJ,0GAA0G;aAC7G;SACF,CAAC,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,8BAA8B,CAAC;QAChD,MAAM,EAAE,IAAI,8BAA8B,EAAE;KAC7C,CAAC,CAAC;IACH,aAAa,CAAC,IAAI,CAAC;QACjB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,WAAW,EAAE,uBAAuB;QACpC,KAAK,EAAE,oBAAoB;QAC3B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE;YACP,MAAM,EAAE,UAAU;YAClB,MAAM,EACJ,sHAAsH;SACzH;KACF,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tachu/host-defaults",
|
|
3
|
+
"version": "1.0.0-rc.0",
|
|
4
|
+
"description": "Default host wiring for Tachu — provider inference, semantic retrieval facade, capability checks. Shared by CLI and non-CLI hosts.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"README_ZH.md",
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"tachu",
|
|
24
|
+
"host",
|
|
25
|
+
"agent",
|
|
26
|
+
"llm",
|
|
27
|
+
"bun",
|
|
28
|
+
"typescript"
|
|
29
|
+
],
|
|
30
|
+
"author": "Tachu Contributors",
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"homepage": "https://github.com/dangaogit/tachu#readme",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/dangaogit/tachu.git",
|
|
36
|
+
"directory": "packages/host-defaults"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/dangaogit/tachu/issues"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"bun": ">=1.3.14"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@tachu/core": "1.0.0-rc.0",
|
|
50
|
+
"@tachu/extensions": "1.0.0-rc.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "bun run clean && bunx tsc -p tsconfig.build.json && bun ../../scripts/copy-md-assets.ts",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"clean": "rm -rf dist",
|
|
56
|
+
"test": "bun test",
|
|
57
|
+
"test:coverage": "bun test --coverage"
|
|
58
|
+
}
|
|
59
|
+
}
|