@waterwx/dsh-novel-forge 1.2.0 → 1.3.1

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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Diagnose the harness LLM path properly: build a cordis context, mount
3
+ * LlmRuntime + deepseek plugin, and check what ctx.llm.stream returns.
4
+ * Run from deepseek-harness-master (has tsx).
5
+ */
6
+ import { Context } from '@deepseek-ai/cordis'
7
+ import LlmRuntime from '@deepseek-ai/dsh-llm'
8
+ import { createUserMessage, BlockAssembler } from '@deepseek-ai/dsh-llm'
9
+ import * as DeepSeekPlugin from '@deepseek-ai/dsh-llm-deepseek'
10
+ import { readFileSync } from 'node:fs'
11
+
12
+ const outline = readFileSync('D:\\ryan work\\harness\\plugins\\novel-forge\\scripts\\outline-sample.txt', 'utf8')
13
+
14
+ const system = [
15
+ '你是一位资深网文编辑兼设定架构师。你会收到一份小说大纲,请把它提炼成结构化的「设定圣经」(Story Bible),供后续写作时严格引用。',
16
+ '1. 忠于大纲,不自行发明大纲之外的设定。',
17
+ '输出必须是合法 JSON 对象,不要输出任何其他文字。',
18
+ 'JSON 结构:',
19
+ '{"genre": "题材与基调一句话", "worldRules": ["规则1"], "characters": [], "redLines": [], "style": []}',
20
+ ].join('\n')
21
+
22
+ const ctx = new Context()
23
+ console.log('before plugin, ctx.llm =', typeof ctx.llm)
24
+ ctx.plugin(LlmRuntime)
25
+ console.log('after LlmRuntime, ctx.llm =', typeof ctx.llm)
26
+ try {
27
+ ctx.plugin(DeepSeekPlugin as never, { reasoningEffort: 'high' } as never)
28
+ console.log('deepseek plugin applied')
29
+ } catch (error) {
30
+ console.error('deepseek plugin failed:', (error as Error).message)
31
+ }
32
+ console.log('providers:', JSON.stringify(ctx.llm?.listProviders() ?? 'NO-LLM'))
33
+
34
+ const messages = [createUserMessage({
35
+ content: [{ type: 'text', text: `请为下面这部小说提炼设定圣经:\n\n${outline}` }],
36
+ source: { kind: 'plugin', plugin: 'dsh-novel-forge' },
37
+ })]
38
+
39
+ const request = {
40
+ provider: 'deepseek-official',
41
+ model: 'deepseek-v4-flash',
42
+ messages,
43
+ system,
44
+ maxTokens: 16000,
45
+ temperature: 0.4,
46
+ }
47
+
48
+ console.log('calling ctx.llm.stream...')
49
+ const assembler = new BlockAssembler()
50
+ let textLen = 0
51
+ let reasoningLen = 0
52
+ let sawFinish = false
53
+ try {
54
+ for await (const chunk of ctx.llm.stream(request as never)) {
55
+ assembler.push(chunk)
56
+ if (chunk.type === 'text-delta') textLen += chunk.text.length
57
+ else if (chunk.type === 'reasoning-delta') reasoningLen += chunk.text.length
58
+ else if (chunk.type === 'finish') sawFinish = true
59
+ }
60
+ const blocks = assembler.blocks()
61
+ console.log('text chars:', textLen)
62
+ console.log('reasoning chars:', reasoningLen)
63
+ console.log('assembled blocks:', blocks.map(b => b.type).join(','))
64
+ console.log('finish:', JSON.stringify(assembler.finish))
65
+ const text = blocks
66
+ .filter((block): block is Extract<typeof block, { type: 'text' }> => block.type === 'text')
67
+ .map(block => block.text)
68
+ .join('\n')
69
+ .trim()
70
+ console.log('complete() would return chars:', text.length)
71
+ console.log('head:', text.slice(0, 200))
72
+ } catch (error) {
73
+ console.error('stream threw:', (error as Error).message)
74
+ }
75
+ process.exit(0)