wiki-graph-sdk 0.7.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/LICENSE +201 -0
- package/README.md +32 -0
- package/dist/archives.cjs +2799 -0
- package/dist/archives.cjs.map +1 -0
- package/dist/archives.d.ts +249 -0
- package/dist/archives.js +2814 -0
- package/dist/archives.js.map +1 -0
- package/dist/conversions.cjs +1332 -0
- package/dist/conversions.cjs.map +1 -0
- package/dist/conversions.d.ts +37 -0
- package/dist/conversions.js +1308 -0
- package/dist/conversions.js.map +1 -0
- package/dist/data/editor/clue_reviewer.jinja +410 -0
- package/dist/data/editor/clue_reviewer_generator.jinja +428 -0
- package/dist/data/editor/revision_feedback.jinja +5 -0
- package/dist/data/editor/text_compressor.jinja +131 -0
- package/dist/data/guaranteed/response_intent_classifier.jinja +8 -0
- package/dist/data/output/epub/cover.xhtml.jinja +13 -0
- package/dist/data/output/epub/nav.xhtml.jinja +12 -0
- package/dist/data/output/epub/package.opf.xml.jinja +39 -0
- package/dist/data/output/epub/section.xhtml.jinja +12 -0
- package/dist/data/topologization/book_coherence_extraction.jinja +223 -0
- package/dist/data/topologization/chunk_extraction.jinja +233 -0
- package/dist/data/topologization/evidence_choice.jinja +38 -0
- package/dist/data/topologization/translate_chunks.jinja +138 -0
- package/dist/data/topologization/user_focused_extraction.jinja +378 -0
- package/dist/default-worker.cjs +1709 -0
- package/dist/default-worker.cjs.map +1 -0
- package/dist/default-worker.d.ts +10 -0
- package/dist/default-worker.js +1705 -0
- package/dist/default-worker.js.map +1 -0
- package/dist/embedding.cjs +1091 -0
- package/dist/embedding.cjs.map +1 -0
- package/dist/embedding.d.ts +26 -0
- package/dist/embedding.js +1062 -0
- package/dist/embedding.js.map +1 -0
- package/dist/entry-context.cjs +91 -0
- package/dist/entry-context.cjs.map +1 -0
- package/dist/entry-context.d.ts +20 -0
- package/dist/entry-context.js +68 -0
- package/dist/entry-context.js.map +1 -0
- package/dist/gc.cjs +731 -0
- package/dist/gc.cjs.map +1 -0
- package/dist/gc.d.ts +14 -0
- package/dist/gc.js +707 -0
- package/dist/gc.js.map +1 -0
- package/dist/index.cjs +4760 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +213 -0
- package/dist/index.js +4808 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs-Dd5PMSId.d.ts +98 -0
- package/dist/llm.cjs +101 -0
- package/dist/llm.cjs.map +1 -0
- package/dist/llm.d.ts +7 -0
- package/dist/llm.js +79 -0
- package/dist/llm.js.map +1 -0
- package/dist/local-config.cjs +1024 -0
- package/dist/local-config.cjs.map +1 -0
- package/dist/local-config.d.ts +14 -0
- package/dist/local-config.js +989 -0
- package/dist/local-config.js.map +1 -0
- package/dist/maintenance.cjs +800 -0
- package/dist/maintenance.cjs.map +1 -0
- package/dist/maintenance.d.ts +24 -0
- package/dist/maintenance.js +778 -0
- package/dist/maintenance.js.map +1 -0
- package/dist/node-platform.cjs +758 -0
- package/dist/node-platform.cjs.map +1 -0
- package/dist/node-platform.d.ts +49 -0
- package/dist/node-platform.js +723 -0
- package/dist/node-platform.js.map +1 -0
- package/dist/planning.cjs +164 -0
- package/dist/planning.cjs.map +1 -0
- package/dist/planning.d.ts +43 -0
- package/dist/planning.js +137 -0
- package/dist/planning.js.map +1 -0
- package/dist/runtime-config.cjs +1155 -0
- package/dist/runtime-config.cjs.map +1 -0
- package/dist/runtime-config.d.ts +50 -0
- package/dist/runtime-config.js +1127 -0
- package/dist/runtime-config.js.map +1 -0
- package/dist/stage.cjs +1265 -0
- package/dist/stage.cjs.map +1 -0
- package/dist/stage.d.ts +16 -0
- package/dist/stage.js +1239 -0
- package/dist/stage.js.map +1 -0
- package/dist/wikispine.cjs +85 -0
- package/dist/wikispine.cjs.map +1 -0
- package/dist/wikispine.d.ts +6 -0
- package/dist/wikispine.js +63 -0
- package/dist/wikispine.js.map +1 -0
- package/dist/worker.cjs +738 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.ts +157 -0
- package/dist/worker.js +715 -0
- package/dist/worker.js.map +1 -0
- package/package.json +151 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { AddBuildJobOptions, BuildJob, BuildJobListOptions, BuildJobEventChunk, BuildJobEvent, BuildJobTarget, ChapterEntry } from 'wiki-graph-core';
|
|
2
|
+
|
|
3
|
+
interface WikiGraphJobBackend {
|
|
4
|
+
add(options: AddBuildJobOptions): Promise<BuildJob>;
|
|
5
|
+
boost(jobId: string): Promise<BuildJob>;
|
|
6
|
+
cancel(jobId: string): Promise<BuildJob>;
|
|
7
|
+
get(jobId: string): Promise<BuildJob>;
|
|
8
|
+
list(options: BuildJobListOptions): Promise<readonly BuildJob[]>;
|
|
9
|
+
pause(jobId: string): Promise<BuildJob>;
|
|
10
|
+
readEventChunk?(job: BuildJob, cursor: number): Promise<BuildJobEventChunk>;
|
|
11
|
+
readEvents?(job: BuildJob): Promise<readonly BuildJobEvent[]>;
|
|
12
|
+
resume(jobId: string): Promise<BuildJob>;
|
|
13
|
+
setTarget(jobId: string, target: BuildJobTarget): Promise<BuildJob>;
|
|
14
|
+
}
|
|
15
|
+
interface WikiGraphJobCreateOptions extends Omit<AddBuildJobOptions, "archive"> {
|
|
16
|
+
readonly archive: string | AddBuildJobOptions["archive"];
|
|
17
|
+
}
|
|
18
|
+
interface WikiGraphJobListOptions extends Omit<BuildJobListOptions, "archive"> {
|
|
19
|
+
readonly archive?: string | BuildJobListOptions["archive"];
|
|
20
|
+
}
|
|
21
|
+
interface WikiGraphJobChapterReference {
|
|
22
|
+
readonly locatedUri: string;
|
|
23
|
+
readonly title: string | null;
|
|
24
|
+
readonly uri: string;
|
|
25
|
+
}
|
|
26
|
+
interface WikiGraphJobEnqueueOptions {
|
|
27
|
+
readonly archive: string;
|
|
28
|
+
readonly boost?: boolean;
|
|
29
|
+
readonly chapterId?: number;
|
|
30
|
+
readonly chapterIds?: readonly number[];
|
|
31
|
+
readonly chapterPath?: string;
|
|
32
|
+
readonly depth?: number;
|
|
33
|
+
readonly llmJSON?: string;
|
|
34
|
+
readonly prompt?: string;
|
|
35
|
+
readonly target?: BuildJobTarget;
|
|
36
|
+
}
|
|
37
|
+
interface WikiGraphJobEnqueueResult {
|
|
38
|
+
readonly created: readonly {
|
|
39
|
+
readonly chapter: ChapterEntry;
|
|
40
|
+
readonly job: WikiGraphJob;
|
|
41
|
+
}[];
|
|
42
|
+
readonly skipped: readonly {
|
|
43
|
+
readonly chapter: ChapterEntry;
|
|
44
|
+
readonly reason: string;
|
|
45
|
+
}[];
|
|
46
|
+
}
|
|
47
|
+
interface WikiGraphJobEnqueuePlan {
|
|
48
|
+
readonly ready: readonly ChapterEntry[];
|
|
49
|
+
readonly skipped: readonly {
|
|
50
|
+
readonly chapter: ChapterEntry;
|
|
51
|
+
readonly reason: string;
|
|
52
|
+
}[];
|
|
53
|
+
}
|
|
54
|
+
interface WikiGraphJobEventsOptions {
|
|
55
|
+
readonly from?: "beginning" | "now";
|
|
56
|
+
readonly pollIntervalMs?: number;
|
|
57
|
+
readonly signal?: AbortSignal;
|
|
58
|
+
}
|
|
59
|
+
type WikiGraphJobEventListener = (event: BuildJobEvent) => void | Promise<void>;
|
|
60
|
+
interface WikiGraphJobSubscriptionOptions extends WikiGraphJobEventsOptions {
|
|
61
|
+
readonly onError?: (error: unknown) => void;
|
|
62
|
+
}
|
|
63
|
+
interface WikiGraphJobRuntime {
|
|
64
|
+
run<T>(operation: () => Promise<T> | T, signal?: AbortSignal, options?: {
|
|
65
|
+
readonly skipHomeBootstrap?: boolean;
|
|
66
|
+
}): Promise<T>;
|
|
67
|
+
}
|
|
68
|
+
declare class WikiGraphJobManager {
|
|
69
|
+
#private;
|
|
70
|
+
constructor(runtime: WikiGraphJobRuntime, backend?: WikiGraphJobBackend);
|
|
71
|
+
create(options: WikiGraphJobCreateOptions): Promise<WikiGraphJob>;
|
|
72
|
+
clean(): Promise<number>;
|
|
73
|
+
get(jobId: string): Promise<WikiGraphJob>;
|
|
74
|
+
resolveId(reference: string): Promise<string>;
|
|
75
|
+
list(options?: WikiGraphJobListOptions): Promise<readonly WikiGraphJob[]>;
|
|
76
|
+
resolveChapters(jobs: readonly BuildJob[]): Promise<ReadonlyMap<string, WikiGraphJobChapterReference>>;
|
|
77
|
+
resolveChapter(job: BuildJob): Promise<WikiGraphJobChapterReference | undefined>;
|
|
78
|
+
enqueue(options: WikiGraphJobEnqueueOptions): Promise<WikiGraphJobEnqueueResult>;
|
|
79
|
+
planEnqueue(options: WikiGraphJobEnqueueOptions): Promise<WikiGraphJobEnqueuePlan>;
|
|
80
|
+
close(): void;
|
|
81
|
+
trackSubscription(controller: AbortController): () => void;
|
|
82
|
+
}
|
|
83
|
+
declare class WikiGraphJob {
|
|
84
|
+
#private;
|
|
85
|
+
constructor(manager: WikiGraphJobManager, runtime: WikiGraphJobRuntime, backend: WikiGraphJobBackend, snapshot: BuildJob);
|
|
86
|
+
get id(): string;
|
|
87
|
+
get snapshot(): BuildJob;
|
|
88
|
+
status(): Promise<BuildJob>;
|
|
89
|
+
pause(): Promise<BuildJob>;
|
|
90
|
+
resume(): Promise<BuildJob>;
|
|
91
|
+
cancel(): Promise<BuildJob>;
|
|
92
|
+
boost(): Promise<BuildJob>;
|
|
93
|
+
setTarget(target: BuildJobTarget): Promise<BuildJob>;
|
|
94
|
+
events(options?: WikiGraphJobEventsOptions): AsyncIterable<BuildJobEvent>;
|
|
95
|
+
subscribe(listener: WikiGraphJobEventListener, options?: WikiGraphJobSubscriptionOptions): () => void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { type WikiGraphJobRuntime as W, WikiGraphJobManager as a, WikiGraphJob as b, type WikiGraphJobBackend as c, type WikiGraphJobChapterReference as d, type WikiGraphJobCreateOptions as e, type WikiGraphJobEnqueueOptions as f, type WikiGraphJobEnqueuePlan as g, type WikiGraphJobEnqueueResult as h, type WikiGraphJobEventListener as i, type WikiGraphJobEventsOptions as j, type WikiGraphJobListOptions as k, type WikiGraphJobSubscriptionOptions as l };
|
package/dist/llm.cjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
globalThis.__WIKIGRAPH_DATA_DIR__ ??= require("path").resolve(__dirname, "data");
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/llm.ts
|
|
22
|
+
var llm_exports = {};
|
|
23
|
+
__export(llm_exports, {
|
|
24
|
+
buildWikiGraphLLMOptions: () => buildWikiGraphLLMOptions
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(llm_exports);
|
|
27
|
+
var import_anthropic = require("@ai-sdk/anthropic");
|
|
28
|
+
var import_google = require("@ai-sdk/google");
|
|
29
|
+
var import_openai = require("@ai-sdk/openai");
|
|
30
|
+
var import_openai_compatible = require("@ai-sdk/openai-compatible");
|
|
31
|
+
function buildWikiGraphLLMOptions(config) {
|
|
32
|
+
const llm = config.llm;
|
|
33
|
+
if (llm?.provider === void 0 || llm.model === void 0) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model."
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
model: createLanguageModel(llm.provider, llm.model, {
|
|
40
|
+
apiKey: llm.apiKey,
|
|
41
|
+
baseURL: llm.baseURL,
|
|
42
|
+
name: llm.name
|
|
43
|
+
}),
|
|
44
|
+
...config.concurrent?.request === void 0 ? {} : { concurrent: config.concurrent.request }
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function createLanguageModel(provider, model, options) {
|
|
48
|
+
switch (provider) {
|
|
49
|
+
case "anthropic": {
|
|
50
|
+
const anthropic = (0, import_anthropic.createAnthropic)({
|
|
51
|
+
...options.apiKey === void 0 ? {} : { apiKey: options.apiKey },
|
|
52
|
+
...options.name === void 0 ? {} : { name: options.name }
|
|
53
|
+
});
|
|
54
|
+
return anthropic(model);
|
|
55
|
+
}
|
|
56
|
+
case "google": {
|
|
57
|
+
const google = (0, import_google.createGoogleGenerativeAI)({
|
|
58
|
+
...options.apiKey === void 0 ? {} : { apiKey: options.apiKey },
|
|
59
|
+
...options.name === void 0 ? {} : { name: options.name }
|
|
60
|
+
});
|
|
61
|
+
return google(model);
|
|
62
|
+
}
|
|
63
|
+
case "openai": {
|
|
64
|
+
if (options.baseURL !== void 0) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
"openai does not accept llm.baseURL or baseURL in --llm JSON. Use openai-compatible for third-party OpenAI-style APIs."
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const openai = (0, import_openai.createOpenAI)({
|
|
70
|
+
...options.apiKey === void 0 ? {} : { apiKey: options.apiKey },
|
|
71
|
+
...options.name === void 0 ? {} : { name: options.name }
|
|
72
|
+
});
|
|
73
|
+
return openai(model);
|
|
74
|
+
}
|
|
75
|
+
case "openai-compatible": {
|
|
76
|
+
if (options.baseURL === void 0) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"openai-compatible requires llm.baseURL or baseURL in --llm JSON."
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const openaiCompatible = (0, import_openai_compatible.createOpenAICompatible)({
|
|
82
|
+
baseURL: options.baseURL,
|
|
83
|
+
name: options.name ?? createOpenAICompatibleName(options.baseURL),
|
|
84
|
+
...options.apiKey === void 0 ? {} : { apiKey: options.apiKey }
|
|
85
|
+
});
|
|
86
|
+
return openaiCompatible(model);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function createOpenAICompatibleName(baseURL) {
|
|
91
|
+
try {
|
|
92
|
+
return new URL(baseURL).hostname;
|
|
93
|
+
} catch {
|
|
94
|
+
return "openai-compatible";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
buildWikiGraphLLMOptions
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=llm.cjs.map
|
package/dist/llm.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/llm.ts"],"sourcesContent":["import type { WikiGraphLLMOptions } from \"wiki-graph-core\";\n\nimport { createAnthropic } from \"@ai-sdk/anthropic\";\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\n\nimport type {\n WikiGraphProvider,\n WikiGraphRuntimeConfig,\n} from \"./runtime-config.js\";\n\nexport function buildWikiGraphLLMOptions(\n config: WikiGraphRuntimeConfig,\n): WikiGraphLLMOptions {\n const llm = config.llm;\n\n if (llm?.provider === undefined || llm.model === undefined) {\n throw new Error(\n \"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model.\",\n );\n }\n\n return {\n model: createLanguageModel(llm.provider, llm.model, {\n apiKey: llm.apiKey,\n baseURL: llm.baseURL,\n name: llm.name,\n }),\n ...(config.concurrent?.request === undefined\n ? {}\n : { concurrent: config.concurrent.request }),\n };\n}\n\nfunction createLanguageModel(\n provider: WikiGraphProvider,\n model: string,\n options: {\n readonly apiKey: string | undefined;\n readonly baseURL: string | undefined;\n readonly name: string | undefined;\n },\n) {\n switch (provider) {\n case \"anthropic\": {\n const anthropic = createAnthropic({\n ...(options.apiKey === undefined ? {} : { apiKey: options.apiKey }),\n ...(options.name === undefined ? {} : { name: options.name }),\n });\n\n return anthropic(model);\n }\n case \"google\": {\n const google = createGoogleGenerativeAI({\n ...(options.apiKey === undefined ? {} : { apiKey: options.apiKey }),\n ...(options.name === undefined ? {} : { name: options.name }),\n });\n\n return google(model);\n }\n case \"openai\": {\n if (options.baseURL !== undefined) {\n throw new Error(\n \"openai does not accept llm.baseURL or baseURL in --llm JSON. Use openai-compatible for third-party OpenAI-style APIs.\",\n );\n }\n\n const openai = createOpenAI({\n ...(options.apiKey === undefined ? {} : { apiKey: options.apiKey }),\n ...(options.name === undefined ? {} : { name: options.name }),\n });\n\n return openai(model);\n }\n case \"openai-compatible\": {\n if (options.baseURL === undefined) {\n throw new Error(\n \"openai-compatible requires llm.baseURL or baseURL in --llm JSON.\",\n );\n }\n\n const openaiCompatible = createOpenAICompatible({\n baseURL: options.baseURL,\n name: options.name ?? createOpenAICompatibleName(options.baseURL),\n ...(options.apiKey === undefined ? {} : { apiKey: options.apiKey }),\n });\n\n return openaiCompatible(model);\n }\n }\n}\n\nfunction createOpenAICompatibleName(baseURL: string): string {\n try {\n return new URL(baseURL).hostname;\n } catch {\n return \"openai-compatible\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAAgC;AAChC,oBAAyC;AACzC,oBAA6B;AAC7B,+BAAuC;AAOhC,SAAS,yBACd,QACqB;AACrB,QAAM,MAAM,OAAO;AAEnB,MAAI,KAAK,aAAa,UAAa,IAAI,UAAU,QAAW;AAC1D,UAAM,IAAI;AAAA,MACR;AAA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AM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,YAAM,uBAAmB,iDAAuB;AAAA,QAC9C,SAAS,QAAQ;AAAA,QACjB,MAAM,QAAQ,QAAQ,2BAA2B,QAAQ,OAAO;AAAA,QAChE,GAAI,QAAQ,WAAW,SAAY,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;AAAA,MACnE,CAAC;AAED,aAAO,iBAAiB,KAAK;AAAA,IAC/B;AAAA,EACF;AACF;AAEA,SAAS,2BAA2B,SAAyB;AAC3D,MAAI;AACF,WAAO,IAAI,IAAI,OAAO,EAAE;AAAA,EAC1B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WikiGraphLLMOptions } from 'wiki-graph-core';
|
|
2
|
+
import { WikiGraphRuntimeConfig } from './runtime-config.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
declare function buildWikiGraphLLMOptions(config: WikiGraphRuntimeConfig): WikiGraphLLMOptions;
|
|
6
|
+
|
|
7
|
+
export { buildWikiGraphLLMOptions };
|
package/dist/llm.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { fileURLToPath as __WIKIGRAPH_FILE_URL_TO_PATH__ } from "url";
|
|
2
|
+
import { resolve as __WIKIGRAPH_RESOLVE__ } from "path";
|
|
3
|
+
globalThis.__WIKIGRAPH_DATA_DIR__ ??= __WIKIGRAPH_RESOLVE__(__WIKIGRAPH_FILE_URL_TO_PATH__(new URL("./data", import.meta.url)));
|
|
4
|
+
|
|
5
|
+
// src/llm.ts
|
|
6
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
7
|
+
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
8
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
9
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
10
|
+
function buildWikiGraphLLMOptions(config) {
|
|
11
|
+
const llm = config.llm;
|
|
12
|
+
if (llm?.provider === void 0 || llm.model === void 0) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
model: createLanguageModel(llm.provider, llm.model, {
|
|
19
|
+
apiKey: llm.apiKey,
|
|
20
|
+
baseURL: llm.baseURL,
|
|
21
|
+
name: llm.name
|
|
22
|
+
}),
|
|
23
|
+
...config.concurrent?.request === void 0 ? {} : { concurrent: config.concurrent.request }
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function createLanguageModel(provider, model, options) {
|
|
27
|
+
switch (provider) {
|
|
28
|
+
case "anthropic": {
|
|
29
|
+
const anthropic = createAnthropic({
|
|
30
|
+
...options.apiKey === void 0 ? {} : { apiKey: options.apiKey },
|
|
31
|
+
...options.name === void 0 ? {} : { name: options.name }
|
|
32
|
+
});
|
|
33
|
+
return anthropic(model);
|
|
34
|
+
}
|
|
35
|
+
case "google": {
|
|
36
|
+
const google = createGoogleGenerativeAI({
|
|
37
|
+
...options.apiKey === void 0 ? {} : { apiKey: options.apiKey },
|
|
38
|
+
...options.name === void 0 ? {} : { name: options.name }
|
|
39
|
+
});
|
|
40
|
+
return google(model);
|
|
41
|
+
}
|
|
42
|
+
case "openai": {
|
|
43
|
+
if (options.baseURL !== void 0) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"openai does not accept llm.baseURL or baseURL in --llm JSON. Use openai-compatible for third-party OpenAI-style APIs."
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const openai = createOpenAI({
|
|
49
|
+
...options.apiKey === void 0 ? {} : { apiKey: options.apiKey },
|
|
50
|
+
...options.name === void 0 ? {} : { name: options.name }
|
|
51
|
+
});
|
|
52
|
+
return openai(model);
|
|
53
|
+
}
|
|
54
|
+
case "openai-compatible": {
|
|
55
|
+
if (options.baseURL === void 0) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"openai-compatible requires llm.baseURL or baseURL in --llm JSON."
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const openaiCompatible = createOpenAICompatible({
|
|
61
|
+
baseURL: options.baseURL,
|
|
62
|
+
name: options.name ?? createOpenAICompatibleName(options.baseURL),
|
|
63
|
+
...options.apiKey === void 0 ? {} : { apiKey: options.apiKey }
|
|
64
|
+
});
|
|
65
|
+
return openaiCompatible(model);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function createOpenAICompatibleName(baseURL) {
|
|
70
|
+
try {
|
|
71
|
+
return new URL(baseURL).hostname;
|
|
72
|
+
} catch {
|
|
73
|
+
return "openai-compatible";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
buildWikiGraphLLMOptions
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=llm.js.map
|
package/dist/llm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/llm.ts"],"sourcesContent":["import type { WikiGraphLLMOptions } from \"wiki-graph-core\";\n\nimport { createAnthropic } from \"@ai-sdk/anthropic\";\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\n\nimport type {\n WikiGraphProvider,\n WikiGraphRuntimeConfig,\n} from \"./runtime-config.js\";\n\nexport function buildWikiGraphLLMOptions(\n config: WikiGraphRuntimeConfig,\n): WikiGraphLLMOptions {\n const llm = config.llm;\n\n if (llm?.provider === undefined || llm.model === undefined) {\n throw new Error(\n \"Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model.\",\n );\n }\n\n return {\n model: createLanguageModel(llm.provider, llm.model, {\n apiKey: llm.apiKey,\n baseURL: llm.baseURL,\n name: llm.name,\n }),\n ...(config.concurrent?.request === undefined\n ? {}\n : { concurrent: config.concurrent.request }),\n };\n}\n\nfunction createLanguageModel(\n provider: WikiGraphProvider,\n model: string,\n options: {\n readonly apiKey: string | undefined;\n readonly baseURL: string | undefined;\n readonly name: string | undefined;\n },\n) {\n switch (provider) {\n case \"anthropic\": {\n const anthropic = createAnthropic({\n ...(options.apiKey === undefined ? {} : { apiKey: options.apiKey }),\n ...(options.name === undefined ? {} : { name: options.name }),\n });\n\n return anthropic(model);\n }\n case \"google\": {\n const google = createGoogleGenerativeAI({\n ...(options.apiKey === undefined ? {} : { apiKey: options.apiKey }),\n ...(options.name === undefined ? {} : { name: options.name }),\n });\n\n return google(model);\n }\n case \"openai\": {\n if (options.baseURL !== undefined) {\n throw new Error(\n \"openai does not accept llm.baseURL or baseURL in --llm JSON. Use openai-compatible for third-party OpenAI-style APIs.\",\n );\n }\n\n const openai = createOpenAI({\n ...(options.apiKey === undefined ? {} : { apiKey: options.apiKey }),\n ...(options.name === undefined ? {} : { name: options.name }),\n });\n\n return openai(model);\n }\n case \"openai-compatible\": {\n if (options.baseURL === undefined) {\n throw new Error(\n \"openai-compatible requires llm.baseURL or baseURL in --llm JSON.\",\n );\n }\n\n const openaiCompatible = createOpenAICompatible({\n baseURL: options.baseURL,\n name: options.name ?? createOpenAICompatibleName(options.baseURL),\n ...(options.apiKey === undefined ? {} : { apiKey: options.apiKey }),\n });\n\n return openaiCompatible(model);\n }\n }\n}\n\nfunction createOpenAICompatibleName(baseURL: string): string {\n try {\n return new URL(baseURL).hostname;\n } catch {\n return \"openai-compatible\";\n }\n}\n"],"mappings":";;;;;AAEA,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AACzC,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AAOhC,SAAS,yBACd,QACqB;AACrB,QAAM,MAAM,OAAO;AAEnB,MAAI,KAAK,aAAa,UAAa,IAAI,UAAU,QAAW;AAC1D,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SA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