@wanji_dsh/dsh-sales 0.10.0 → 0.10.2

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.
Files changed (138) hide show
  1. package/.dsh/skills/wanji-sales-assistant/SKILL.md +28 -3
  2. package/.dsh/skills/wanji-sales-assistant/references/draft-review.md +2 -2
  3. package/.dsh/skills/wanji-sales-assistant/references/wechat-delivery.md +24 -0
  4. package/README.md +24 -4
  5. package/README.zh.md +51 -4
  6. package/dist/client.js +9632 -664
  7. package/dist/host.js +3200 -958
  8. package/dist/types/{agent-evaluators.d.ts → agent-evaluators-v2.d.ts} +17 -3
  9. package/dist/types/agent-knowledge.d.ts +11 -2
  10. package/dist/types/agent.d.ts +21 -8
  11. package/dist/types/commercial-boundary.d.ts +7 -0
  12. package/dist/types/customer-intent.d.ts +49 -0
  13. package/dist/types/customer-materials.d.ts +49 -0
  14. package/dist/types/dialogue-tasks.d.ts +10 -0
  15. package/dist/types/draft-edits.d.ts +7 -0
  16. package/dist/types/evaluation-client.d.ts +2 -6
  17. package/dist/types/fact-proof.d.ts +2 -1
  18. package/dist/types/generation-progress.d.ts +32 -0
  19. package/dist/types/generation-runtime.d.ts +17 -0
  20. package/dist/types/generation-session-route.d.ts +5 -0
  21. package/dist/types/generation-sessions.d.ts +36 -0
  22. package/dist/types/host.d.ts +15 -0
  23. package/dist/types/knowledge-host.d.ts +22 -3
  24. package/dist/types/knowledge-judgment-delivery.d.ts +2 -0
  25. package/dist/types/knowledge-judgments.d.ts +12 -0
  26. package/dist/types/knowledge-privacy.d.ts +2 -0
  27. package/dist/types/knowledge-turns.d.ts +22 -0
  28. package/dist/types/langfuse-config.d.ts +1 -0
  29. package/dist/types/langfuse-outbox.d.ts +10 -2
  30. package/dist/types/material-catalog.d.ts +17 -0
  31. package/dist/types/material-metadata.d.ts +4 -0
  32. package/dist/types/material-reply.d.ts +24 -0
  33. package/dist/types/material-request.d.ts +45 -0
  34. package/dist/types/material-retrieval.d.ts +29 -0
  35. package/dist/types/model.d.ts +23 -2
  36. package/dist/types/open-generation.d.ts +5 -2
  37. package/dist/types/open-review.d.ts +39 -15
  38. package/dist/types/operation-evidence.d.ts +7 -0
  39. package/dist/types/percentage-quote.d.ts +6 -0
  40. package/dist/types/plan-projection.d.ts +2 -0
  41. package/dist/types/product-evidence.d.ts +4 -0
  42. package/dist/types/question-relay.d.ts +24 -0
  43. package/dist/types/question-route.d.ts +4 -0
  44. package/dist/types/question-tracing.d.ts +84 -0
  45. package/dist/types/quote-context.d.ts +9 -5
  46. package/dist/types/response-contract.d.ts +10 -0
  47. package/dist/types/retrieval-queries.d.ts +4 -0
  48. package/dist/types/review-turn.d.ts +6 -0
  49. package/dist/types/sales-context-types.d.ts +15 -0
  50. package/dist/types/semantic-rerank.d.ts +9 -0
  51. package/dist/types/sending-policy.d.ts +2 -0
  52. package/dist/types/server/intent-evaluation.d.ts +27 -0
  53. package/dist/types/server/intent-host.d.ts +17 -0
  54. package/dist/types/stream-preview.d.ts +11 -0
  55. package/dist/types/turn-packet.d.ts +21 -8
  56. package/dist/types/turn-plan.d.ts +19 -7
  57. package/dist/types/update/activity.d.ts +1 -1
  58. package/dist/types/verified-arithmetic.d.ts +5 -0
  59. package/dist/types/voice-examples.d.ts +1 -0
  60. package/dist/types/wechat/cua-approval.d.ts +36 -0
  61. package/dist/types/wechat/cua-sender.d.ts +160 -0
  62. package/dist/types/wechat/cua-vision.d.ts +31 -0
  63. package/dist/types/wechat/delivery.d.ts +47 -0
  64. package/dist/types/wechat/intent-scheduler.d.ts +26 -0
  65. package/dist/types/wechat/repository-client.d.ts +1 -1
  66. package/dist/types/wechat/routes.d.ts +9 -7
  67. package/dist/types/wechat/service.d.ts +8 -3
  68. package/dist/types/wechat/types.d.ts +5 -0
  69. package/dist/types/wechat-draft-input.d.ts +3 -0
  70. package/dist/types/wechat-voice.d.ts +3 -0
  71. package/dist/types/weknora-http.d.ts +8 -0
  72. package/dist/wechat-repository-worker.js +248 -22
  73. package/docs/agent-knowledge-observation.md +58 -0
  74. package/docs/customer-material-retrieval.md +48 -0
  75. package/docs/licenses/ccount@2.0.1.txt +24 -0
  76. package/docs/licenses/character-entities@2.0.2.txt +24 -0
  77. package/docs/licenses/debug@4.4.3.txt +21 -0
  78. package/docs/licenses/decode-named-character-reference@1.3.0.txt +24 -0
  79. package/docs/licenses/dequal@2.0.3.txt +23 -0
  80. package/docs/licenses/devlop@1.1.0.txt +24 -0
  81. package/docs/licenses/escape-string-regexp@5.0.0.txt +11 -0
  82. package/docs/licenses/longest-streak@3.1.0.txt +24 -0
  83. package/docs/licenses/markdown-table@3.1.0.txt +24 -0
  84. package/docs/licenses/mdast-util-find-and-replace@3.0.4.txt +24 -0
  85. package/docs/licenses/mdast-util-from-markdown@2.0.3.txt +24 -0
  86. package/docs/licenses/mdast-util-gfm-autolink-literal@2.1.0.txt +24 -0
  87. package/docs/licenses/mdast-util-gfm-footnote@2.1.0.txt +24 -0
  88. package/docs/licenses/mdast-util-gfm-strikethrough@2.0.1.txt +24 -0
  89. package/docs/licenses/mdast-util-gfm-table@2.0.1.txt +24 -0
  90. package/docs/licenses/mdast-util-gfm-task-list-item@2.0.1.txt +24 -0
  91. package/docs/licenses/mdast-util-gfm@3.0.0.txt +24 -0
  92. package/docs/licenses/mdast-util-phrasing@4.1.0.txt +25 -0
  93. package/docs/licenses/mdast-util-to-markdown@2.2.3.txt +24 -0
  94. package/docs/licenses/mdast-util-to-string@4.0.0.txt +24 -0
  95. package/docs/licenses/micromark-core-commonmark@2.0.4.txt +24 -0
  96. package/docs/licenses/micromark-extension-gfm-autolink-literal@2.1.0.txt +24 -0
  97. package/docs/licenses/micromark-extension-gfm-footnote@2.1.0.txt +24 -0
  98. package/docs/licenses/micromark-extension-gfm-strikethrough@2.1.0.txt +24 -0
  99. package/docs/licenses/micromark-extension-gfm-table@2.1.2.txt +24 -0
  100. package/docs/licenses/micromark-extension-gfm-tagfilter@2.0.0.txt +24 -0
  101. package/docs/licenses/micromark-extension-gfm-task-list-item@2.1.0.txt +24 -0
  102. package/docs/licenses/micromark-extension-gfm@3.0.0.txt +24 -0
  103. package/docs/licenses/micromark-factory-destination@2.0.1.txt +24 -0
  104. package/docs/licenses/micromark-factory-label@2.0.1.txt +24 -0
  105. package/docs/licenses/micromark-factory-space@2.1.0.txt +24 -0
  106. package/docs/licenses/micromark-factory-title@2.0.1.txt +24 -0
  107. package/docs/licenses/micromark-factory-whitespace@2.0.1.txt +24 -0
  108. package/docs/licenses/micromark-util-character@2.1.1.txt +24 -0
  109. package/docs/licenses/micromark-util-chunked@2.0.1.txt +24 -0
  110. package/docs/licenses/micromark-util-classify-character@2.0.1.txt +24 -0
  111. package/docs/licenses/micromark-util-combine-extensions@2.0.1.txt +24 -0
  112. package/docs/licenses/micromark-util-decode-numeric-character-reference@2.0.2.txt +24 -0
  113. package/docs/licenses/micromark-util-decode-string@2.0.1.txt +24 -0
  114. package/docs/licenses/micromark-util-edit-map@1.0.0.txt +24 -0
  115. package/docs/licenses/micromark-util-encode@2.0.1.txt +24 -0
  116. package/docs/licenses/micromark-util-html-tag-name@2.0.1.txt +24 -0
  117. package/docs/licenses/micromark-util-normalize-identifier@2.0.1.txt +24 -0
  118. package/docs/licenses/micromark-util-resolve-all@2.0.1.txt +24 -0
  119. package/docs/licenses/micromark-util-sanitize-uri@2.0.1.txt +24 -0
  120. package/docs/licenses/micromark-util-subtokenize@2.1.0.txt +24 -0
  121. package/docs/licenses/micromark-util-symbol@2.0.1.txt +24 -0
  122. package/docs/licenses/micromark-util-types@2.0.3.txt +24 -0
  123. package/docs/licenses/micromark@4.0.3.txt +24 -0
  124. package/docs/licenses/ms@2.1.3.txt +23 -0
  125. package/docs/licenses/unist-util-is@6.0.1.txt +24 -0
  126. package/docs/licenses/unist-util-stringify-position@4.0.0.txt +24 -0
  127. package/docs/licenses/unist-util-visit-parents@6.1.0.txt +24 -0
  128. package/docs/licenses/unist-util-visit@5.2.0.txt +24 -0
  129. package/docs/licenses/zwitch@2.0.4.txt +24 -0
  130. package/docs/sales-agent-evaluation-v2.md +102 -0
  131. package/docs/wechat-sync.md +23 -0
  132. package/package.json +20 -7
  133. package/runtime/customer-materials.json +1935 -0
  134. package/runtime/documented-operation-references.json +123 -0
  135. package/runtime/operation-references.json +352 -0
  136. package/runtime/product-references.json +10 -0
  137. package/runtime/wechat-manifest.json +1 -1
  138. package/runtime/wechat-ocr-arm64 +0 -0
@@ -1,4 +1,4 @@
1
- export declare function evaluatorDefinitions(provider: string, model: string): {
1
+ export declare function knowledgeEvaluatorDefinitions(provider: string, model: string): {
2
2
  name: string;
3
3
  type: string;
4
4
  description: string;
@@ -13,16 +13,30 @@ export declare function evaluatorDefinitions(provider: string, model: string): {
13
13
  variableMapping: {
14
14
  variable: string;
15
15
  source: string;
16
+ jsonPath: string;
16
17
  }[];
17
18
  outputDefinition: {
19
+ dataType: string;
20
+ categories: string[];
21
+ shouldAllowMultipleMatches: boolean;
22
+ scoreValueInstructions: string;
23
+ scoreReasoningInstructions: string;
24
+ minValue?: undefined;
25
+ maxValue?: undefined;
26
+ } | {
18
27
  dataType: string;
19
28
  minValue: number;
20
29
  maxValue: number;
21
30
  scoreValueInstructions: string;
22
31
  scoreReasoningInstructions: string;
32
+ categories?: undefined;
33
+ shouldAllowMultipleMatches?: undefined;
23
34
  };
24
35
  }[];
25
- export declare function agentEvaluationRule(ids: string[]): {
36
+ export declare function knowledgeEvaluationRules(evaluators: {
37
+ id: string;
38
+ name: string;
39
+ }[]): {
26
40
  name: string;
27
41
  enabled: boolean;
28
42
  sampling: number;
@@ -42,4 +56,4 @@ export declare function agentEvaluationRule(ids: string[]): {
42
56
  evaluatorAssignments: {
43
57
  evaluatorId: string;
44
58
  }[];
45
- };
59
+ }[];
@@ -28,6 +28,7 @@ interface Options {
28
28
  knowledgeBaseId: string;
29
29
  toolPrefix: string;
30
30
  send?: (event: ObservationEvent) => Promise<void>;
31
+ validate?: (event: ObservationEvent) => Promise<void>;
31
32
  }
32
33
  export declare function agentMetricValues(event: ObservationEvent): Record<string, number>;
33
34
  export declare function deliverAgentEvent(event: ObservationEvent): Promise<void>;
@@ -35,6 +36,7 @@ export declare class AgentKnowledgeObserver {
35
36
  private readonly options;
36
37
  private readonly started;
37
38
  readonly outbox: LangfuseOutbox;
39
+ private readonly judgments;
38
40
  private readonly ready;
39
41
  private readonly lifetime;
40
42
  private readonly instanceId;
@@ -50,6 +52,9 @@ export declare class AgentKnowledgeObserver {
50
52
  private dropped;
51
53
  private delivery?;
52
54
  private initialized;
55
+ private readonly turns;
56
+ private v2;
57
+ private sanitize;
53
58
  constructor(options: Options);
54
59
  private eligible;
55
60
  private begin;
@@ -59,16 +64,20 @@ export declare class AgentKnowledgeObserver {
59
64
  /** Harness emits a frozen final result. Snapshot synchronously, persist asynchronously. */
60
65
  finish(exec: KnowledgeExecution, result: KnowledgeOutcome): void;
61
66
  drain(): Promise<void>;
67
+ sessionEvent(sessionId: string, event: {
68
+ type: string;
69
+ data: any;
70
+ }): true | undefined;
62
71
  private recover;
63
72
  flush(): Promise<void>;
64
73
  status(): Promise<{
74
+ pending: number;
75
+ otherPending: number;
65
76
  blocked: number;
66
77
  unfinished: number;
67
78
  inFlight: number;
68
79
  dropped: number;
69
80
  errorCode: string | undefined;
70
- pending: number;
71
- otherPending: number;
72
81
  enabled: boolean;
73
82
  }>;
74
83
  close(): Promise<void>;
@@ -2,9 +2,12 @@ import { type CustomerProgress } from './turn-packet.ts';
2
2
  export { buildReviewPrompt, applyDeliveryReview, reviewSentences } from './delivery-review.ts';
3
3
  import { type SalesKnowledgeContext } from './sales-context-types.ts';
4
4
  import type { Contact } from './model.ts';
5
+ import type { GenerationOptions, GenerationStream, GenerationTimings } from './generation-progress.ts';
6
+ import { type CustomerMaterials } from './customer-materials.ts';
5
7
  /** Uses the Harness connection carrier, including its existing authentication. */
6
8
  export interface RpcTransport {
7
9
  call(channel: string, endpoint: string, payload: unknown, signal?: AbortSignal): Promise<unknown>;
10
+ follow?(sessionId: string, signal: AbortSignal): GenerationStream;
8
11
  }
9
12
  export interface SalesReply {
10
13
  judgment: string;
@@ -13,6 +16,7 @@ export interface SalesReply {
13
16
  no_send: boolean;
14
17
  progress?: CustomerProgress;
15
18
  knowledge?: SalesKnowledgeContext;
19
+ timings?: GenerationTimings;
16
20
  }
17
21
  /** Separate output channels are mandatory; a narrative report is never pasted as customer copy. */
18
22
  export declare function parseReply(text: string, allowedMoney?: readonly string[], customerMoney?: readonly string[]): SalesReply;
@@ -34,6 +38,7 @@ export declare function buildPrompt(contact: Contact, latest: string, knowledge?
34
38
  };
35
39
  latest_customer_message: string;
36
40
  sources: Record<string, import("./turn-packet.ts").Evidence>;
41
+ selection_rule: string;
37
42
  current_company_facts: {
38
43
  key: string;
39
44
  sourceId: string;
@@ -130,11 +135,14 @@ export declare function buildPrompt(contact: Contact, latest: string, knowledge?
130
135
  start_basis?: "activation" | "payment" | "agreement";
131
136
  } | null;
132
137
  calculation: import("./quote-context.ts").QuoteCalculation | null;
138
+ response_contract: import("./response-contract.ts").AnswerContract;
133
139
  data_scope: "anonymized-only" | "customer-authorized";
140
+ material_context: CustomerMaterials | null;
134
141
  company_conflicts: string[];
135
142
  knowledge: {
136
143
  contextId: string | null;
137
144
  checkedAt: string | null;
145
+ materials_available: boolean;
138
146
  policy_candidates: Record<string, unknown>[];
139
147
  rule: string;
140
148
  };
@@ -145,18 +153,23 @@ export declare function buildPrompt(contact: Contact, latest: string, knowledge?
145
153
  authority: "method_only";
146
154
  }[];
147
155
  previous_progress: {
148
- decisions: {
156
+ pending?: import("./dialogue-tasks.ts").PendingCompanyTask[];
157
+ decisions: (import("./turn-packet.ts").BoundItem & {
158
+ topic: string;
159
+ meaning: string;
160
+ } & {
149
161
  source_id: string;
150
- quote: string;
151
- }[];
152
- artifacts: {
162
+ })[];
163
+ artifacts: (import("./turn-packet.ts").BoundItem & {
164
+ kind: "sample" | "intro" | "confirmation";
165
+ status: "requested" | "received" | "reviewed";
166
+ } & {
153
167
  source_id: string;
154
- quote: string;
155
- }[];
168
+ })[];
169
+ stage: "exploring" | "evaluating" | "confirming" | "paused" | "declined";
156
170
  source_id: string;
157
171
  quote: string;
158
- stage?: "exploring" | "evaluating" | "confirming" | "paused" | "declined" | undefined;
159
172
  } | null;
160
173
  }): string;
161
174
  /** Each generation and delivery review own fresh Sessions; neither can inherit another merchant. */
162
- export declare function generateReply(rpc: RpcTransport, workspaceId: string, contact: Contact, latest: string, signal: AbortSignal): Promise<SalesReply>;
175
+ export declare function generateReply(rpc: RpcTransport, workspaceId: string, contact: Contact, latest: string, signal: AbortSignal, options?: GenerationOptions): Promise<SalesReply>;
@@ -0,0 +1,7 @@
1
+ import type { Contact } from './model.ts';
2
+ import type { TurnPacket } from './turn-packet.ts';
3
+ /** Bind an explicitly attributed return preference to customer evidence, never
4
+ * previous sales prose. A new clear correction supersedes the older preference. */
5
+ export declare function assertAttributedCustomerTerms(packet: TurnPacket, text: string): void;
6
+ /** Customer preferences never create bilateral terms. Only bound owner records can. */
7
+ export declare function assertCommercialBoundary(contact: Contact, text: string): void;
@@ -0,0 +1,49 @@
1
+ export declare const intentSemanticPolicyVersion = 2;
2
+ export declare const intentPolicyVersion = 3;
3
+ export declare const intentProducts: readonly ["erp", "wanjitang"];
4
+ export type IntentProduct = typeof intentProducts[number];
5
+ export type IntentGrade = 'A' | 'B' | 'C' | 'D';
6
+ export type IntentStage = 'committed' | 'engaged' | 'exploring' | 'paused' | 'declined' | 'service';
7
+ export interface IntentEvidence {
8
+ id: string;
9
+ at: string;
10
+ source: 'wechat' | 'call';
11
+ quote: string;
12
+ }
13
+ export interface ProductIntent {
14
+ stage: IntentStage;
15
+ score: number | null;
16
+ evidence: IntentEvidence;
17
+ }
18
+ export interface CustomerIntent {
19
+ version: number;
20
+ policyVersion?: number;
21
+ status: 'pending' | 'ready' | 'failed';
22
+ updatedAt?: string;
23
+ crm?: {
24
+ grade: IntentGrade;
25
+ score: number;
26
+ };
27
+ products: Partial<Record<IntentProduct, ProductIntent>>;
28
+ crmUnavailable?: boolean;
29
+ evaluatedVersion?: number;
30
+ retryAt?: number;
31
+ crmChecked?: boolean;
32
+ crmLookupFailed?: boolean;
33
+ }
34
+ export declare const intentAnchors: Record<IntentGrade, number>;
35
+ export declare const productIntentNames: Record<IntentProduct, string>;
36
+ export declare function gradeOf(score: number): IntentGrade;
37
+ export declare function rankedIntent(intent?: CustomerIntent): {
38
+ product: "erp" | "wanjitang";
39
+ score: number;
40
+ grade: IntentGrade;
41
+ item: ProductIntent;
42
+ } | undefined;
43
+ export declare function compareIntent<T extends {
44
+ intent?: CustomerIntent;
45
+ time: string;
46
+ id: string;
47
+ }>(a: T, b: T): number;
48
+ export declare function newerIntent(a?: CustomerIntent, b?: CustomerIntent): CustomerIntent | undefined;
49
+ export declare function intentGuidance(intent?: CustomerIntent): string;
@@ -0,0 +1,49 @@
1
+ import type { TurnPacket } from './turn-packet.ts';
2
+ export declare const MATERIAL_KB_ID = "1f93aee2-6d66-42d7-8b7a-b5fe5d094550";
3
+ export declare const materialKinds: readonly ["video", "document", "image", "any"];
4
+ export declare const materialEditions: readonly ["门店版", "专业版", "标准版", "unknown"];
5
+ export interface MaterialNeed {
6
+ query: string;
7
+ kind: typeof materialKinds[number];
8
+ edition: typeof materialEditions[number];
9
+ source_id: string;
10
+ }
11
+ export interface CustomerMaterial {
12
+ id: string;
13
+ knowledgeId: string;
14
+ assetId: string;
15
+ kind: 'video' | 'document' | 'image';
16
+ edition: string;
17
+ title: string;
18
+ fileUrl: string;
19
+ url: string;
20
+ fileSha256: string;
21
+ version: string;
22
+ page?: number;
23
+ text: string;
24
+ boundary: string;
25
+ }
26
+ export interface CustomerMaterials {
27
+ status: 'available' | 'not_found' | 'unavailable' | 'edition_required';
28
+ knowledgeBaseId: string;
29
+ checkedAt: string;
30
+ contextId?: string;
31
+ items: CustomerMaterial[];
32
+ }
33
+ export declare function materialRequestConstraints(packet: TurnPacket): {
34
+ required: boolean;
35
+ kind: "document" | "video" | "image" | "any" | null;
36
+ edition: string;
37
+ source_id: string;
38
+ };
39
+ export declare function parseMaterialNeed(value: unknown, packet: TurnPacket): MaterialNeed | undefined;
40
+ export declare const allowMaterialResend: (latest: string) => boolean;
41
+ export declare function assetUrl(value: string, sha: string): string;
42
+ export declare function parseCustomerMaterials(value: unknown): CustomerMaterials;
43
+ export declare function withCustomerMaterials(packet: TurnPacket, materials: CustomerMaterials): TurnPacket;
44
+ export declare function sentMaterialUrls(packet: TurnPacket): string[];
45
+ /** Select actual source URLs, never manufacture a link or report a send receipt. */
46
+ export declare function renderCustomerMaterials(wechat: string, materials: CustomerMaterials | null | undefined): string;
47
+ export declare function selectedMaterialIds(wechat: string, materials: CustomerMaterials): string[];
48
+ /** A known available requested file must be in the delivered copy, not just promised. */
49
+ export declare function assertCustomerMaterialDelivery(wechat: string, materials: CustomerMaterials | null | undefined, required: boolean): void;
@@ -0,0 +1,10 @@
1
+ import type { TurnPacket, CustomerProgress, Evidence, SalesActionKind } from './turn-packet.ts';
2
+ export interface PendingCompanyTask {
3
+ topic: string;
4
+ source_id: string;
5
+ quote: string;
6
+ basis: string;
7
+ }
8
+ /** Change detector only, never an approval, authorization token, or proof of execution. */
9
+ export declare function companyBasis(sources: Record<string, Evidence>): string;
10
+ export declare function advanceDialogueTasks(progress: CustomerProgress, packet: TurnPacket, action: SalesActionKind): CustomerProgress;
@@ -2,6 +2,13 @@ import type { SalesReply } from './agent.ts';
2
2
  import type { OpenIssue } from './open-review.ts';
3
3
  import type { TurnPacket } from './turn-packet.ts';
4
4
  import type { TurnPlan } from './turn-plan.ts';
5
+ export declare function editUnits(draft: SalesReply): {
6
+ id: string;
7
+ field: "wechat" | "judgment" | "next_step";
8
+ text: string;
9
+ start: number;
10
+ end: number;
11
+ }[];
5
12
  export declare function applyDraftEdits(draft: SalesReply, text: string): SalesReply;
6
13
  /** Pure layout repair after atomic deletions; never invents replacement business content. */
7
14
  export declare function normalizeEditedLayout(text: string): string;
@@ -1,8 +1,5 @@
1
- export interface EvaluationConnection {
2
- baseUrl: string;
3
- apiKey: string;
4
- tenantId?: string;
5
- }
1
+ import { type WeKnoraConnection } from './weknora-http.ts';
2
+ export type EvaluationConnection = WeKnoraConnection;
6
3
  export interface EvaluationService {
7
4
  execute(input: unknown, signal: AbortSignal): Promise<unknown>;
8
5
  }
@@ -11,7 +8,6 @@ interface EvaluationOptions {
11
8
  maxResults: number;
12
9
  requestTimeoutMs: number;
13
10
  }
14
- /** Connection values are accepted only from the Host's installation config. */
15
11
  export declare function resolveEvaluationConnection(raw: unknown): EvaluationConnection | undefined;
16
12
  /** All returned scope metadata must agree, including nested run snapshots. */
17
13
  export declare function assertEvaluationScope(value: unknown, kb: string, depth?: number): void;
@@ -1,6 +1,7 @@
1
1
  import type { TurnPacket } from './turn-packet.ts';
2
2
  import type { SalesReply } from './agent.ts';
3
3
  import type { OpenIssue } from './open-review.ts';
4
+ export declare const operationProofRules = "\u6D89\u53CA\u8865\u5F55\u3001\u5E76\u53D1\u6216\u7EA0\u9519\u65F6\uFF0C\u5148\u7ED9\u5F53\u524D\u53EF\u77E5\u7684\u6838\u5BF9\u5EFA\u8BAE\uFF1A\u4EE5\u8131\u654F\u51ED\u636E\u6838\u5BF9\u771F\u5B9E\u6536\u8D2D\u4E0E\u9500\u552E\u8BB0\u5F55\u3001\u6210\u672C\u548C\u673A\u5668\u8EAB\u4EFD\uFF0C\u518D\u6838\u5F53\u524D\u7248\u672C\u5141\u8BB8\u7684\u8865\u5F55/\u66F4\u6B63\u65B9\u5F0F\u3002\u4E0D\u5F97\u65AD\u8A00\u865A\u6784\u5355\u636E\u5FC5\u80FD\u5E73\u5E93\u5B58\uFF1B\u4E0D\u77E5\u9053\u5165\u53E3\u65F6\u4E0D\u80FD\u5EFA\u8BAE\u968F\u4FBF\u627E\u5165\u53E3\u5F55\u3002\u6D4B\u8BD5\u9700\u5728\u9694\u79BB\u73AF\u5883\u4F7F\u7528\u865A\u6784\u6837\u4F8B\u5355\uFF0C\u73AF\u5883\u672A\u786E\u8BA4\u5148\u6838\u89C4\u5219\uFF0C\u4E0D\u80FD\u5728\u771F\u5B9E\u4E1A\u52A1\u5355\u636E\u6539\u503C\u8BD5\u9519\u3002\u4E0D\u786E\u5B9A\u7684\u64CD\u4F5C\u3001\u6743\u9650\u6216\u7EA0\u9519\u7ED3\u679C\u4E0D\u80FD\u901A\u8FC7\u201C\u76F4\u63A5\u6539\u4E00\u4E0B\u201D\u6765\u9A8C\u8BC1\uFF0C\u4E5F\u4E0D\u80FD\u56E0\u6B64\u6263\u4F4F\u5DF2\u77E5\u7684\u6838\u5BF9\u5185\u5BB9\u3002\u6761\u4EF6\u6027\u95EE\u9898\u4E0D\u8BC1\u660E\u6539\u52A8\u5DF2\u7ECF\u53D1\u751F\uFF1B\u82E5\u5DF2\u6709\u6539\u52A8\uFF0C\u53EF\u53EA\u8BFB\u56DE\u770B\u73B0\u6709\u5B57\u6BB5\u53CA\u5F53\u65F6\u4FDD\u5B58\u65F6\u70B9\uFF0C\u4E0D\u91CD\u65B0\u5199\u5165\u6D4B\u8BD5\uFF1B\u82E5\u5C1A\u672A\u53D1\u751F\uFF0C\u5148\u6838\u89C4\u5219\uFF0C\u4E0D\u865A\u6784\u5386\u53F2\u6539\u5355\u3002\u53EA\u8BFB\u6838\u5BF9\u4E0D\u80FD\u8BEF\u5224\u4E3A\u6267\u884C\u5199\u5165\u3002";
4
5
  export declare function factBasis(packet: TurnPacket): Record<string, {
5
6
  text: string;
6
7
  authority: string;
@@ -23,4 +24,4 @@ export declare function parseFactProof(text: string, draft: SalesReply, packet:
23
24
  claims: ProvenClaim[];
24
25
  };
25
26
  export declare function buildFactProofPrompt(packet: TurnPacket, draft: SalesReply, customerOnly?: boolean): string;
26
- export declare function buildEntailmentPrompt(claims: ReturnType<typeof parseFactProof>['claims'], latest: string): string;
27
+ export declare function buildEntailmentPrompt(claims: ReturnType<typeof parseFactProof>['claims'], latest: string, selectionRule?: string, packet?: TurnPacket): string;
@@ -0,0 +1,32 @@
1
+ /** User-visible work phases; internal model analysis never becomes preview text. */
2
+ export type GenerationStage = 'context' | 'knowledge' | 'planning' | 'writing' | 'reviewing' | 'validating';
3
+ /** A transient observation, separate from the reviewed and editable sales draft. */
4
+ export interface GenerationProgress {
5
+ stage: GenerationStage;
6
+ preview?: string;
7
+ elapsedMs: number;
8
+ }
9
+ /** Measured from generateReply entry, excluding the earlier CRM cold-load phase. */
10
+ export interface GenerationTimings {
11
+ phases: Partial<Record<GenerationStage, number>>;
12
+ /** Aggregate operation durations can overlap and must not be summed as wall time. */
13
+ operations?: Record<string, {
14
+ calls: number;
15
+ ms: number;
16
+ }>;
17
+ firstTokenMs?: number;
18
+ /** First writer text delta measured from its prompt submission, not from planning. */
19
+ writerFirstTokenMs?: number;
20
+ firstPreviewMs?: number;
21
+ verifiedMs?: number;
22
+ totalMs?: number;
23
+ }
24
+ /** Optional observers must not make a valid draft depend on its presentation. */
25
+ export interface GenerationOptions {
26
+ onProgress?(value: GenerationProgress): void;
27
+ onTimings?(value: GenerationTimings): void;
28
+ }
29
+ /** The current authenticated Harness Remote follow handle. */
30
+ export interface GenerationStream extends AsyncIterable<unknown> {
31
+ dispose(): void;
32
+ }
@@ -0,0 +1,17 @@
1
+ import type { GenerationServices } from './generation-sessions.ts';
2
+ export declare const SALES_GENERATION_PRESET = "wanji-sales-generation";
3
+ /** Permanent product-owned composition; never borrows the coding preset or its AGENTS/tools. */
4
+ export declare function createGenerationRuntime(sdk: {
5
+ agents: any;
6
+ presets: any;
7
+ defaults: any;
8
+ registry: any;
9
+ titles?: {
10
+ rename(session: any, title: string): unknown;
11
+ };
12
+ }, configuredModel?: {
13
+ provider: string;
14
+ model: string;
15
+ }): GenerationServices & {
16
+ close(): Promise<void>;
17
+ };
@@ -0,0 +1,5 @@
1
+ import { type GenerationServices } from './generation-sessions.ts';
2
+ import type { HostContext } from './knowledge-host.ts';
3
+ export declare const GENERATION_SESSION_ENDPOINT = "wanji-sales-generation/session";
4
+ /** Authenticated owner Fetch surface. The lease is the capability, never an arbitrary session id. */
5
+ export declare function registerGenerationSessionRoute(ctx: HostContext, services: () => GenerationServices | undefined): void;
@@ -0,0 +1,36 @@
1
+ export interface GenerationHandle {
2
+ agent: {
3
+ id: string;
4
+ };
5
+ titleApplied?: boolean;
6
+ dispose(): Promise<void>;
7
+ }
8
+ export interface GenerationServices {
9
+ create(cwd: string, sessionId: string, signal: AbortSignal, title?: string): Promise<GenerationHandle>;
10
+ workspace(id: string): {
11
+ path: string;
12
+ attachSession?(id: string): Promise<void>;
13
+ } | undefined;
14
+ }
15
+ /** Owns only the handles it creates; caller cannot name an arbitrary desktop session to close. */
16
+ export declare class GenerationSessions {
17
+ private leases;
18
+ private closed;
19
+ private services;
20
+ private ttlMs;
21
+ constructor(services: GenerationServices, ttlMs?: number);
22
+ create(workspaceId: string, leaseId: string | undefined, signal: AbortSignal, title?: string): Promise<{
23
+ leaseId: string;
24
+ sessionId: string;
25
+ titleApplied: boolean;
26
+ }>;
27
+ /** Acknowledges cleanup scheduling while the broker retains and retries every disposer. */
28
+ releaseInBackground(leaseId: string, workspaceId: string): {
29
+ released: boolean;
30
+ queued?: boolean;
31
+ };
32
+ release(leaseId: string, workspaceId: string): Promise<{
33
+ released: boolean;
34
+ }>;
35
+ close(): Promise<void>;
36
+ }
@@ -4,6 +4,8 @@ import { type KnowledgeExecution, type KnowledgeOutcome } from './agent-knowledg
4
4
  import { type HostContext as ProfileHostContext } from './server/host.ts';
5
5
  import { type ProfileConfig } from './server/config.ts';
6
6
  import { type KnowledgeConfig, type HostContext as KnowledgeHostContext } from './knowledge-host.ts';
7
+ import { SalesQuestionObserver } from './question-tracing.ts';
8
+ import { type SalesQuestionRelay } from './question-relay.ts';
7
9
  export interface Config extends Omit<ProfileConfig, 'requestTimeoutMs'>, KnowledgeConfig {
8
10
  wechatComponentRoot?: string;
9
11
  wechatRuntimeBaseUrl?: string;
@@ -13,11 +15,24 @@ export interface Config extends Omit<ProfileConfig, 'requestTimeoutMs'>, Knowled
13
15
  export interface HostContext extends ProfileHostContext {
14
16
  on?(name: 'tools/execute', listener: (exec: KnowledgeExecution, next: () => Promise<any>) => Promise<any>): () => void;
15
17
  on?(name: 'tools/result', listener: (exec: KnowledgeExecution, result: KnowledgeOutcome) => void): () => void;
18
+ on?(name: 'tools/post-execute', listener: (exec: KnowledgeExecution, result: KnowledgeOutcome, next: () => Promise<KnowledgePostDecision>) => Promise<KnowledgePostDecision>): () => void;
19
+ on?(name: 'session/event', listener: (...args: Parameters<SalesQuestionObserver['observe']>) => void): () => void;
20
+ get?(name: 'speechToText'): ReturnType<NonNullable<ProfileHostContext['get']>>;
21
+ get?(name: 'wanjiSalesQuestionRelay'): SalesQuestionRelay | undefined;
16
22
  inject(services: string[], callback: (child: KnowledgeHostContext) => void): unknown;
17
23
  }
24
+ type KnowledgePostDecision = {
25
+ kind: 'block';
26
+ } | {
27
+ kind: 'accept';
28
+ content?: unknown;
29
+ value?: unknown;
30
+ additionalContexts?: unknown[];
31
+ };
18
32
  /** One standard schema validates both capabilities before either registers. */
19
33
  export declare const Config: Schema<Partial<Config>, Config>;
20
34
  export declare const name = "wanji-sales";
21
35
  export declare const inject: string[];
22
36
  /** Knowledge routes activate when the web connection service is available; headless CRM stays usable. */
23
37
  export declare function apply(ctx: HostContext, rawConfig?: unknown): void;
38
+ export {};
@@ -2,6 +2,8 @@ import { type KnowledgeObserver } from './langfuse-collector.ts';
2
2
  import { EvaluationOutbox } from './evaluation-outbox.ts';
3
3
  import { type EvaluationConnection, type EvaluationService } from './evaluation-client.ts';
4
4
  import { type RpcResult } from './knowledge-types.ts';
5
+ import { type WeKnoraConnection } from './weknora-http.ts';
6
+ import { MaterialRetriever } from './material-retrieval.ts';
5
7
  /** Structural slice of Harness tools; no provider credentials are accepted here. */
6
8
  export interface ToolService {
7
9
  register?(definition: {
@@ -17,6 +19,9 @@ export interface ToolService {
17
19
  };
18
20
  execute(args: unknown, exec: {
19
21
  signal: AbortSignal;
22
+ agent?: {
23
+ id: string;
24
+ };
20
25
  }): Promise<unknown>;
21
26
  timeoutMs?: number;
22
27
  isConcurrencySafe?(): boolean;
@@ -47,7 +52,17 @@ export interface ToolService {
47
52
  }>;
48
53
  }
49
54
  export interface KnowledgeConfig {
55
+ materialRetrievalEnabled?: boolean;
56
+ materialKnowledgeBaseIds?: string[];
57
+ materialToolPrefix?: string;
58
+ evaluationKnowledgeIds?: string[];
59
+ evaluationMaterialIds?: string[];
60
+ semanticRerank?: boolean;
50
61
  agentKnowledgeTracing: boolean;
62
+ salesQuestionTracing: boolean;
63
+ materialKnowledgeBaseId?: string;
64
+ materialAssetBaseUrl?: string;
65
+ materialMetadata?: WeKnoraConnection;
51
66
  langfuseConfigFile?: string;
52
67
  evaluation?: EvaluationConnection;
53
68
  toolVersion: string;
@@ -66,7 +81,7 @@ export interface HostPeer {
66
81
  kind: string;
67
82
  };
68
83
  }
69
- export type KnowledgeHandler = (endpoint: string, payload: unknown, signal: AbortSignal, peer: HostPeer) => Promise<RpcResult<unknown>>;
84
+ export type KnowledgeHandler = (endpoint: string, payload: unknown, signal: AbortSignal, peer: HostPeer, sessionId?: string) => Promise<RpcResult<unknown>>;
70
85
  export interface HostContext {
71
86
  workspaceRegistry?: {
72
87
  list(): {
@@ -90,10 +105,14 @@ export interface HostContext {
90
105
  }
91
106
  export declare function resolveKnowledgeConfig(input?: unknown): KnowledgeConfig;
92
107
  /** Owns peer-scoped document grants and drops them when this plugin instance unloads. */
108
+ export type SemanticRanker = (query: string, hits: import('./knowledge-types.ts').KnowledgeHit[], signal: AbortSignal, options?: {
109
+ relevantOnly?: boolean;
110
+ }) => Promise<import('./knowledge-types.ts').KnowledgeHit[]>;
111
+ export type QueryExpander = (query: string, signal: AbortSignal) => Promise<string[]>;
93
112
  export declare function createKnowledgeHost(tools: ToolService, config: KnowledgeConfig, lifetime?: AbortSignal, outbox?: EvaluationOutbox, evaluationOrWorkspaces?: EvaluationService | (() => {
94
113
  id: string;
95
114
  title: string;
96
115
  path: string;
97
- }[]), injectedObserver?: KnowledgeObserver): KnowledgeHandler;
116
+ }[]), injectedObserver?: KnowledgeObserver, rerank?: SemanticRanker, materialOverride?: MaterialRetriever, expandQuery?: QueryExpander): KnowledgeHandler;
98
117
  export declare const inject: string[];
99
- export declare function apply(ctx: HostContext, config?: unknown, agentStatus?: () => Promise<import('./knowledge-types.ts').AgentTracingStatus>): void;
118
+ export declare function apply(ctx: HostContext, config?: unknown, agentStatus?: () => Promise<import('./knowledge-types.ts').AgentTracingStatus>, rerank?: SemanticRanker, expandQuery?: QueryExpander, recordQuestion?: (input: import('./question-tracing.ts').ObservedQuestion, outcome: import('./question-tracing.ts').QuestionOutcome) => Promise<void>): void;
@@ -0,0 +1,2 @@
1
+ import type { ObservationEvent } from './langfuse-outbox.ts';
2
+ export declare function deliverKnowledgeJudgment(event: ObservationEvent, request?: (path: string, body?: unknown) => Promise<any>): Promise<void>;
@@ -0,0 +1,12 @@
1
+ /** Only actual returned chunks are judge evidence. Model arithmetic is never authoritative. */
2
+ export interface JudgeChunk {
3
+ id: string;
4
+ rank: number;
5
+ knowledge_id: string;
6
+ chunk_id: string;
7
+ content: string;
8
+ truncated: boolean;
9
+ metadata: Record<string, unknown>;
10
+ }
11
+ export declare function retrievalEvidence(value: any): JudgeChunk[];
12
+ export declare function validateRelevance(reason: string, evidence: JudgeChunk[]): Record<string, number>;
@@ -0,0 +1,2 @@
1
+ /** V2 adds original questions/answers, so require a private key and redact before journaling. */
2
+ export declare function readEvaluationPrivacy(path: unknown): Promise<(value: any) => any>;
@@ -0,0 +1,22 @@
1
+ import { type JudgeChunk } from './knowledge-judgments.ts';
2
+ type Turn = {
3
+ turn: number;
4
+ question: string;
5
+ answer: string;
6
+ evidence: JudgeChunk[];
7
+ searched: boolean;
8
+ complete: boolean;
9
+ startedAt: string;
10
+ };
11
+ /** Prospective events only. Never reads deprecated session snapshots or inherits another turn. */
12
+ export declare class KnowledgeTurns {
13
+ private turns;
14
+ current(id: string): Turn | undefined;
15
+ accept(id: string, event: {
16
+ type: string;
17
+ data: any;
18
+ }): Turn | undefined;
19
+ evidence(id: string, value: any, scopeKnown: boolean): void;
20
+ invalidate(id: string): void;
21
+ }
22
+ export {};
@@ -3,6 +3,7 @@ export interface Destination {
3
3
  baseUrl: string;
4
4
  projectId: string;
5
5
  credentialsRef: string;
6
+ allowPrivateHttp?: true;
6
7
  }
7
8
  export interface Credentials {
8
9
  publicKey: string;
@@ -6,7 +6,12 @@ export interface RunContext {
6
6
  config: Record<string, unknown>;
7
7
  created_at: string;
8
8
  }
9
+ export type QuestionSource = 'sales-reply' | 'sales-agent' | 'knowledge-search';
9
10
  export interface ObservationEvent {
11
+ question?: {
12
+ sessionId: string;
13
+ source: QuestionSource;
14
+ };
10
15
  agent?: {
11
16
  sessionId: string;
12
17
  callId: string;
@@ -17,7 +22,7 @@ export interface ObservationEvent {
17
22
  };
18
23
  id: string;
19
24
  target: Destination;
20
- kind: 'search' | 'read';
25
+ kind: 'search' | 'read' | 'answer' | 'question';
21
26
  startedAt: string;
22
27
  elapsedMs: number;
23
28
  knowledgeBaseId: string;
@@ -29,6 +34,7 @@ export interface ObservationEvent {
29
34
  export declare class LangfuseOutbox {
30
35
  private writes;
31
36
  private flushing;
37
+ private lastAttempted?;
32
38
  private readonly directory;
33
39
  constructor(directory: string);
34
40
  remove(event: ObservationEvent): Promise<void>;
@@ -39,5 +45,7 @@ export declare class LangfuseOutbox {
39
45
  blocked: number;
40
46
  }>;
41
47
  put(value: ObservationEvent): Promise<void>;
42
- flush(send: (value: ObservationEvent) => Promise<void>, signal: AbortSignal, eligible?: (value: ObservationEvent) => boolean): Promise<void>;
48
+ flush(send: (value: ObservationEvent) => Promise<void>, signal: AbortSignal, eligible?: (value: ObservationEvent) => boolean, options?: {
49
+ independentPending?: boolean;
50
+ }): Promise<void>;
43
51
  }
@@ -0,0 +1,17 @@
1
+ import { type MaterialSearch, type ResolvedMaterial } from './material-request.ts';
2
+ import type { ReadMaterialMetadata } from './material-metadata.ts';
3
+ export interface MaterialConfig {
4
+ knowledgeBaseId: string;
5
+ assetBaseUrl: string;
6
+ }
7
+ export declare function resolveMaterialConfig(id: unknown, baseUrl: unknown): MaterialConfig | undefined;
8
+ /** Redact both the structured tool value and its re-rendered content for agent diagnostics. */
9
+ export declare function hideMaterialUrls(value: unknown, assetBaseUrl: string): unknown;
10
+ type Invoke = (suffix: string, args: Record<string, unknown>, signal: AbortSignal) => Promise<unknown>;
11
+ export declare function createMaterialCatalog(config: MaterialConfig, maxResults: number, invoke: Invoke, readMetadata: ReadMaterialMetadata, head?: typeof fetch): {
12
+ find(query: string, owner: object | string, signal: AbortSignal): Promise<MaterialSearch>;
13
+ resolve(requestId: string, id: string, owner: object | string, signal: AbortSignal): Promise<ResolvedMaterial | {
14
+ status: "empty";
15
+ }>;
16
+ };
17
+ export {};
@@ -0,0 +1,4 @@
1
+ import { type WeKnoraConnection } from './weknora-http.ts';
2
+ export type ReadMaterialMetadata = (id: string, signal: AbortSignal) => Promise<Record<string, unknown> | undefined>;
3
+ /** Only the Host can read metadata, for a document ID selected by knowledge search. */
4
+ export declare function createMaterialMetadataReader(connection: WeKnoraConnection, requestTimeoutMs: number): ReadMaterialMetadata;