@wowok/agent-mcp 2.3.14 → 2.3.18
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/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/config/runtime.d.ts +26 -0
- package/dist/config/runtime.js +217 -0
- package/dist/customer/index.d.ts +9 -0
- package/dist/customer/index.js +9 -0
- package/dist/customer/industry-risks.d.ts +40 -0
- package/dist/customer/industry-risks.js +438 -0
- package/dist/customer/info-puzzle.d.ts +102 -0
- package/dist/customer/info-puzzle.js +312 -0
- package/dist/customer/order-monitor.d.ts +75 -0
- package/dist/customer/order-monitor.js +327 -0
- package/dist/customer/order-strategy.d.ts +36 -0
- package/dist/customer/order-strategy.js +373 -0
- package/dist/customer/post-purchase.d.ts +42 -0
- package/dist/customer/post-purchase.js +350 -0
- package/dist/customer/reminder-system.d.ts +42 -0
- package/dist/customer/reminder-system.js +295 -0
- package/dist/customer/risk-assessment.d.ts +8 -0
- package/dist/customer/risk-assessment.js +337 -0
- package/dist/customer/types.d.ts +193 -0
- package/dist/customer/types.js +13 -0
- package/dist/customer/user-preferences.d.ts +70 -0
- package/dist/customer/user-preferences.js +460 -0
- package/dist/experience/experience-reuse.d.ts +10 -0
- package/dist/experience/experience-reuse.js +103 -0
- package/dist/experience/index.d.ts +6 -0
- package/dist/experience/index.js +5 -0
- package/dist/experience/intent-distill.d.ts +3 -0
- package/dist/experience/intent-distill.js +83 -0
- package/dist/experience/realtime-feedback.d.ts +5 -0
- package/dist/experience/realtime-feedback.js +94 -0
- package/dist/experience/types.d.ts +50 -0
- package/dist/experience/types.js +1 -0
- package/dist/experience/user-profile.d.ts +25 -0
- package/dist/experience/user-profile.js +171 -0
- package/dist/index.js +842 -371
- package/dist/knowledge/acquisition-flywheel.d.ts +53 -0
- package/dist/knowledge/acquisition-flywheel.js +192 -0
- package/dist/knowledge/arbitration-trust.d.ts +24 -0
- package/dist/knowledge/arbitration-trust.js +117 -0
- package/dist/knowledge/audit-rules.d.ts +28 -0
- package/dist/knowledge/audit-rules.js +141 -0
- package/dist/knowledge/demand-matching.d.ts +29 -0
- package/dist/knowledge/demand-matching.js +132 -0
- package/dist/knowledge/dynamic-pricing.d.ts +31 -0
- package/dist/knowledge/dynamic-pricing.js +87 -0
- package/dist/knowledge/flywheel-loop.d.ts +87 -0
- package/dist/knowledge/flywheel-loop.js +378 -0
- package/dist/knowledge/glossary.d.ts +18 -0
- package/dist/knowledge/glossary.js +209 -0
- package/dist/knowledge/guard-ledger.d.ts +19 -0
- package/dist/knowledge/guard-ledger.js +219 -0
- package/dist/knowledge/guard-puzzle.d.ts +93 -0
- package/dist/knowledge/guard-puzzle.js +278 -0
- package/dist/knowledge/guard-risk.d.ts +60 -0
- package/dist/knowledge/guard-risk.js +474 -0
- package/dist/knowledge/guard-translation.d.ts +46 -0
- package/dist/knowledge/guard-translation.js +487 -0
- package/dist/knowledge/index.d.ts +77 -0
- package/dist/knowledge/index.js +79 -0
- package/dist/knowledge/industry-evolution.d.ts +82 -0
- package/dist/knowledge/industry-evolution.js +323 -0
- package/dist/knowledge/industry-generalizer.d.ts +17 -0
- package/dist/knowledge/industry-generalizer.js +381 -0
- package/dist/knowledge/industry-registry.d.ts +48 -0
- package/dist/knowledge/industry-registry.js +187 -0
- package/dist/knowledge/intent-metrics.d.ts +42 -0
- package/dist/knowledge/intent-metrics.js +566 -0
- package/dist/knowledge/process-model.d.ts +24 -0
- package/dist/knowledge/process-model.js +160 -0
- package/dist/knowledge/reputation-rules.d.ts +42 -0
- package/dist/knowledge/reputation-rules.js +99 -0
- package/dist/knowledge/reward-templates.d.ts +25 -0
- package/dist/knowledge/reward-templates.js +125 -0
- package/dist/knowledge/safety-rules.d.ts +36 -0
- package/dist/knowledge/safety-rules.js +232 -0
- package/dist/knowledge/tool-constraints.d.ts +30 -0
- package/dist/knowledge/tool-constraints.js +175 -0
- package/dist/knowledge/trust-metrics.d.ts +37 -0
- package/dist/knowledge/trust-metrics.js +138 -0
- package/dist/loop-engineering/diagnose.d.ts +3 -2
- package/dist/loop-engineering/diagnose.js +94 -0
- package/dist/loop-engineering/improve.d.ts +1 -1
- package/dist/loop-engineering/improve.js +52 -1
- package/dist/project/graph.d.ts +71 -0
- package/dist/project/graph.js +314 -0
- package/dist/project/index.d.ts +62 -0
- package/dist/project/index.js +167 -0
- package/dist/project/namespace.d.ts +62 -0
- package/dist/project/namespace.js +181 -0
- package/dist/project/query.d.ts +40 -0
- package/dist/project/query.js +110 -0
- package/dist/safety/confirm-gate.d.ts +17 -0
- package/dist/safety/confirm-gate.js +88 -0
- package/dist/safety/index.d.ts +3 -0
- package/dist/safety/index.js +3 -0
- package/dist/safety/preview.d.ts +2 -0
- package/dist/safety/preview.js +36 -0
- package/dist/schema/call/allocation.d.ts +39 -14
- package/dist/schema/call/arbitration.d.ts +187 -162
- package/dist/schema/call/base.d.ts +1971 -87
- package/dist/schema/call/base.js +135 -3
- package/dist/schema/call/bridge-handler.js +15 -2
- package/dist/schema/call/bridge.d.ts +1478 -53
- package/dist/schema/call/bridge.js +50 -2
- package/dist/schema/call/contact.d.ts +25 -0
- package/dist/schema/call/demand.d.ts +79 -54
- package/dist/schema/call/guard.d.ts +125 -50
- package/dist/schema/call/handler.d.ts +3 -0
- package/dist/schema/call/handler.js +60 -14
- package/dist/schema/call/machine.d.ts +988 -938
- package/dist/schema/call/order.d.ts +25 -0
- package/dist/schema/call/payment.d.ts +25 -0
- package/dist/schema/call/permission.d.ts +244 -219
- package/dist/schema/call/personal.d.ts +25 -0
- package/dist/schema/call/progress.d.ts +25 -0
- package/dist/schema/call/proof.d.ts +62 -12
- package/dist/schema/call/proof.js +3 -3
- package/dist/schema/call/repository.d.ts +101 -76
- package/dist/schema/call/reward.d.ts +55 -30
- package/dist/schema/call/semantic.d.ts +10 -2
- package/dist/schema/call/semantic.js +616 -11
- package/dist/schema/call/service.d.ts +442 -417
- package/dist/schema/call/treasury.d.ts +25 -0
- package/dist/schema/common/index.js +3 -3
- package/dist/schema/config/index.d.ts +18 -0
- package/dist/schema/config/index.js +17 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/local/index.d.ts +237 -81
- package/dist/schema/local/index.js +42 -6
- package/dist/schema/messenger/index.d.ts +1018 -79
- package/dist/schema/messenger/index.js +26 -17
- package/dist/schema/operations.d.ts +3192 -1746
- package/dist/schema/operations.js +93 -98
- package/dist/schema/project/index.d.ts +21 -0
- package/dist/schema/project/index.js +32 -0
- package/dist/schema/query/index.d.ts +2762 -1856
- package/dist/schema/query/index.js +38 -35
- package/dist/schema/schema-query/index.d.ts +33 -0
- package/dist/schema/schema-query/index.js +36 -0
- package/dist/schema/schema-version.d.ts +25 -0
- package/dist/schema/schema-version.js +76 -0
- package/dist/schema/trust/index.d.ts +407 -0
- package/dist/schema/trust/index.js +113 -0
- package/dist/schemas/account_operation.output.json +25 -16
- package/dist/schemas/account_operation.schema.json +1 -1
- package/dist/schemas/bridge_operation.output.json +744 -0
- package/dist/schemas/bridge_operation.schema.json +82 -8
- package/dist/schemas/config_operation.output.json +18 -0
- package/dist/schemas/config_operation.schema.json +34 -0
- package/dist/schemas/guard-node-schema.json +82 -0
- package/dist/schemas/guard2file.schema.json +23 -0
- package/dist/schemas/index.json +19 -1
- package/dist/schemas/local_info_operation.output.json +23 -0
- package/dist/schemas/local_info_operation.schema.json +1 -1
- package/dist/schemas/local_mark_operation.output.json +24 -1
- package/dist/schemas/local_mark_operation.schema.json +4 -4
- package/dist/schemas/machineNode2file.schema.json +23 -0
- package/dist/schemas/messenger_operation.output.json +752 -0
- package/dist/schemas/onchain_events.output.json +718 -0
- package/dist/schemas/onchain_operations.output.json +627 -18
- package/dist/schemas/onchain_operations.schema.json +115 -39
- package/dist/schemas/onchain_operations_allocation.schema.json +23 -0
- package/dist/schemas/onchain_operations_arbitration.schema.json +23 -0
- package/dist/schemas/onchain_operations_contact.schema.json +23 -0
- package/dist/schemas/onchain_operations_demand.schema.json +23 -0
- package/dist/schemas/onchain_operations_gen_passport.schema.json +46 -0
- package/dist/schemas/onchain_operations_guard.schema.json +26 -16
- package/dist/schemas/onchain_operations_machine.schema.json +89 -23
- package/dist/schemas/onchain_operations_order.schema.json +23 -0
- package/dist/schemas/onchain_operations_payment.schema.json +23 -0
- package/dist/schemas/onchain_operations_permission.schema.json +23 -0
- package/dist/schemas/onchain_operations_personal.schema.json +23 -0
- package/dist/schemas/onchain_operations_progress.schema.json +23 -0
- package/dist/schemas/onchain_operations_repository.schema.json +23 -0
- package/dist/schemas/onchain_operations_reward.schema.json +23 -0
- package/dist/schemas/onchain_operations_service.schema.json +23 -0
- package/dist/schemas/onchain_operations_treasury.schema.json +23 -0
- package/dist/schemas/onchain_table_data.output.json +939 -69
- package/dist/schemas/onchain_table_data.schema.json +2 -2
- package/dist/schemas/project_operation.output.json +18 -0
- package/dist/schemas/project_operation.schema.json +42 -0
- package/dist/schemas/query_toolkit.schema.json +360 -368
- package/dist/schemas/schema_query.schema.json +6 -3
- package/dist/schemas/trust_score.output.json +327 -0
- package/dist/schemas/trust_score.schema.json +46 -0
- package/package.json +2 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { distillIntent, extractSignals } from "./intent-distill.js";
|
|
2
|
+
import { getProfile, updateFromOperation } from "./user-profile.js";
|
|
3
|
+
import { findMatches, recordSignature } from "./experience-reuse.js";
|
|
4
|
+
import { EXPERIENCE_LAYER_VERSION } from "./types.js";
|
|
5
|
+
import { isEnabled as isRuntimeEnabled } from "../config/index.js";
|
|
6
|
+
import { recordIndustrySignal } from "../knowledge/flywheel-loop.js";
|
|
7
|
+
export { EXPERIENCE_LAYER_VERSION };
|
|
8
|
+
export function getExperienceFeedback(operation_type, data, baseIntent) {
|
|
9
|
+
try {
|
|
10
|
+
const distilled = distillIntent(operation_type, data, baseIntent);
|
|
11
|
+
const matches = findMatches(distilled.primary_intent, operation_type, data, 3);
|
|
12
|
+
if (matches.length === 0)
|
|
13
|
+
return undefined;
|
|
14
|
+
const topMatch = matches[0];
|
|
15
|
+
const profile = getProfile();
|
|
16
|
+
return formatFeedback(topMatch, matches, distilled.scenario, profile);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function recordOperationOutcome(operation_type, data, baseIntent, outcome, errorCode, referencedObjects = []) {
|
|
23
|
+
try {
|
|
24
|
+
const distilled = distillIntent(operation_type, data, baseIntent);
|
|
25
|
+
const signals = extractSignals(operation_type, data);
|
|
26
|
+
recordSignature({
|
|
27
|
+
intent: distilled.primary_intent,
|
|
28
|
+
scenario: distilled.scenario,
|
|
29
|
+
signals,
|
|
30
|
+
timestamp: Date.now(),
|
|
31
|
+
outcome,
|
|
32
|
+
error_code: errorCode,
|
|
33
|
+
});
|
|
34
|
+
updateFromOperation(distilled.primary_intent, distilled.scenario, outcome, errorCode, referencedObjects);
|
|
35
|
+
try {
|
|
36
|
+
if (isRuntimeEnabled("industry_evolution")) {
|
|
37
|
+
const industryHint = (typeof data?.industry === "string" && data.industry.trim())
|
|
38
|
+
? data.industry.trim()
|
|
39
|
+
: undefined;
|
|
40
|
+
if (industryHint) {
|
|
41
|
+
const signalOutcome = outcome === "success"
|
|
42
|
+
? { success: true }
|
|
43
|
+
: { success: false, error_code: errorCode };
|
|
44
|
+
recordIndustrySignal(industryHint, { type: operation_type, data }, signalOutcome);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function formatFeedback(topMatch, allMatches, scenario, profile) {
|
|
55
|
+
const advice = buildAdviceText(topMatch, allMatches, profile);
|
|
56
|
+
const avoid = collectAvoidList(allMatches, profile);
|
|
57
|
+
const relevance = topMatch.relevance;
|
|
58
|
+
const matchedScenario = scenario ?? topMatch.signature.scenario;
|
|
59
|
+
const feedback = {};
|
|
60
|
+
if (advice)
|
|
61
|
+
feedback.advice = advice;
|
|
62
|
+
if (avoid.length > 0)
|
|
63
|
+
feedback.avoid = avoid;
|
|
64
|
+
if (relevance > 0)
|
|
65
|
+
feedback.relevance = Math.round(relevance * 100) / 100;
|
|
66
|
+
if (matchedScenario)
|
|
67
|
+
feedback.matched_scenario = matchedScenario;
|
|
68
|
+
return feedback;
|
|
69
|
+
}
|
|
70
|
+
function buildAdviceText(topMatch, allMatches, profile) {
|
|
71
|
+
const parts = [];
|
|
72
|
+
if (topMatch.signature.outcome === "success") {
|
|
73
|
+
parts.push(`Historically, ${topMatch.signature.intent} operation succeeded`);
|
|
74
|
+
}
|
|
75
|
+
else if (topMatch.signature.outcome === "failed") {
|
|
76
|
+
parts.push(`Historically, ${topMatch.signature.intent} operation failed (${topMatch.signature.error_code ?? "unknown error"}), pay special attention to parameters`);
|
|
77
|
+
}
|
|
78
|
+
if (profile.expertise_tier === "novice" && allMatches.length > 0) {
|
|
79
|
+
parts.push("It is recommended to carefully check parameters before executing");
|
|
80
|
+
}
|
|
81
|
+
return parts.join("; ") || topMatch.advice;
|
|
82
|
+
}
|
|
83
|
+
function collectAvoidList(matches, profile) {
|
|
84
|
+
const avoid = new Set();
|
|
85
|
+
for (const m of matches) {
|
|
86
|
+
for (const a of m.avoid) {
|
|
87
|
+
avoid.add(a);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const p of profile.frequent_pitfalls) {
|
|
91
|
+
avoid.add(`You often make mistakes at the ${p} step, please be especially careful`);
|
|
92
|
+
}
|
|
93
|
+
return Array.from(avoid).slice(0, 5);
|
|
94
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface UserIntentSignature {
|
|
2
|
+
intent: string;
|
|
3
|
+
scenario?: string;
|
|
4
|
+
signals: Record<string, any>;
|
|
5
|
+
timestamp: number;
|
|
6
|
+
outcome: "success" | "failed" | "partial";
|
|
7
|
+
error_code?: string;
|
|
8
|
+
recovery_path?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface UserProfile {
|
|
11
|
+
expertise_tier: "novice" | "advanced" | "expert";
|
|
12
|
+
preferred_industries: string[];
|
|
13
|
+
risk_appetite: "conservative" | "balanced" | "aggressive";
|
|
14
|
+
frequent_pitfalls: string[];
|
|
15
|
+
reused_objects: string[];
|
|
16
|
+
preferred_confirmation: "minimal" | "standard" | "verbose";
|
|
17
|
+
total_operations: number;
|
|
18
|
+
success_rate: number;
|
|
19
|
+
last_updated: number;
|
|
20
|
+
buyer_signals?: BuyerSignals;
|
|
21
|
+
}
|
|
22
|
+
export interface BuyerSignals {
|
|
23
|
+
purchase_count: number;
|
|
24
|
+
avg_purchase_price_ratio: number;
|
|
25
|
+
discount_usage_count: number;
|
|
26
|
+
referral_usage_count: number;
|
|
27
|
+
dispute_count: number;
|
|
28
|
+
inferred_price_sensitivity?: "low" | "medium" | "high";
|
|
29
|
+
inferred_bargain_hunting?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface DistilledIntent {
|
|
32
|
+
primary_intent: string;
|
|
33
|
+
secondary_intents: string[];
|
|
34
|
+
confidence: number;
|
|
35
|
+
urgency: "low" | "normal" | "high" | "critical";
|
|
36
|
+
scenario?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ExperienceMatch {
|
|
39
|
+
signature: UserIntentSignature;
|
|
40
|
+
relevance: number;
|
|
41
|
+
advice: string;
|
|
42
|
+
avoid: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface ExperienceFeedback {
|
|
45
|
+
advice?: string;
|
|
46
|
+
avoid?: string[];
|
|
47
|
+
relevance?: number;
|
|
48
|
+
matched_scenario?: string;
|
|
49
|
+
}
|
|
50
|
+
export declare const EXPERIENCE_LAYER_VERSION = 1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const EXPERIENCE_LAYER_VERSION = 1;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { UserProfile, BuyerSignals } from "./types.js";
|
|
2
|
+
export declare function getProfile(): UserProfile;
|
|
3
|
+
export interface PurchaseOutcomeInput {
|
|
4
|
+
price: bigint;
|
|
5
|
+
avg_market_price?: bigint;
|
|
6
|
+
used_discount?: boolean;
|
|
7
|
+
used_referral?: boolean;
|
|
8
|
+
has_dispute?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function recordPurchaseOutcome(input: PurchaseOutcomeInput): void;
|
|
11
|
+
export declare function getBuyerSignals(): BuyerSignals;
|
|
12
|
+
export declare function updateFromOperation(intent: string, scenario: string | undefined, outcome: "success" | "failed" | "partial", errorCode: string | undefined, referencedObjects: string[]): void;
|
|
13
|
+
export declare function resetProfile(): void;
|
|
14
|
+
export declare function getProfileStats(): {
|
|
15
|
+
total_operations: number;
|
|
16
|
+
success_rate: number;
|
|
17
|
+
top_scenarios: Array<{
|
|
18
|
+
scenario: string;
|
|
19
|
+
count: number;
|
|
20
|
+
}>;
|
|
21
|
+
top_pitfalls: Array<{
|
|
22
|
+
error_code: string;
|
|
23
|
+
count: number;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
let currentProfile = {
|
|
2
|
+
expertise_tier: "novice",
|
|
3
|
+
preferred_industries: [],
|
|
4
|
+
risk_appetite: "balanced",
|
|
5
|
+
frequent_pitfalls: [],
|
|
6
|
+
reused_objects: [],
|
|
7
|
+
preferred_confirmation: "standard",
|
|
8
|
+
total_operations: 0,
|
|
9
|
+
success_rate: 1.0,
|
|
10
|
+
last_updated: 0,
|
|
11
|
+
};
|
|
12
|
+
let buyerSignals = {
|
|
13
|
+
purchase_count: 0,
|
|
14
|
+
avg_purchase_price_ratio: 1.0,
|
|
15
|
+
discount_usage_count: 0,
|
|
16
|
+
referral_usage_count: 0,
|
|
17
|
+
dispute_count: 0,
|
|
18
|
+
};
|
|
19
|
+
let scenarioCounts = new Map();
|
|
20
|
+
let pitfallCounts = new Map();
|
|
21
|
+
let objectRefs = new Map();
|
|
22
|
+
let successCount = 0;
|
|
23
|
+
let totalCount = 0;
|
|
24
|
+
export function getProfile() {
|
|
25
|
+
return { ...currentProfile, buyer_signals: { ...buyerSignals } };
|
|
26
|
+
}
|
|
27
|
+
export function recordPurchaseOutcome(input) {
|
|
28
|
+
try {
|
|
29
|
+
buyerSignals.purchase_count++;
|
|
30
|
+
if (input.used_discount)
|
|
31
|
+
buyerSignals.discount_usage_count++;
|
|
32
|
+
if (input.used_referral)
|
|
33
|
+
buyerSignals.referral_usage_count++;
|
|
34
|
+
if (input.has_dispute)
|
|
35
|
+
buyerSignals.dispute_count++;
|
|
36
|
+
if (input.avg_market_price && input.avg_market_price > 0n) {
|
|
37
|
+
const ratio = Number((input.price * 100n) / input.avg_market_price) / 100;
|
|
38
|
+
const prevAvg = buyerSignals.avg_purchase_price_ratio;
|
|
39
|
+
const n = buyerSignals.purchase_count;
|
|
40
|
+
buyerSignals.avg_purchase_price_ratio = (prevAvg * (n - 1) + ratio) / n;
|
|
41
|
+
}
|
|
42
|
+
recomputeBuyerInferences();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function recomputeBuyerInferences() {
|
|
48
|
+
const n = buyerSignals.purchase_count;
|
|
49
|
+
if (n >= 3) {
|
|
50
|
+
const avgRatio = buyerSignals.avg_purchase_price_ratio;
|
|
51
|
+
if (avgRatio < 0.9) {
|
|
52
|
+
buyerSignals.inferred_price_sensitivity = "high";
|
|
53
|
+
}
|
|
54
|
+
else if (avgRatio > 1.1) {
|
|
55
|
+
buyerSignals.inferred_price_sensitivity = "low";
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
buyerSignals.inferred_price_sensitivity = "medium";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (n >= 2) {
|
|
62
|
+
const signalCount = buyerSignals.discount_usage_count + buyerSignals.referral_usage_count;
|
|
63
|
+
const ratio = signalCount / n;
|
|
64
|
+
buyerSignals.inferred_bargain_hunting = Math.min(1, ratio);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function getBuyerSignals() {
|
|
68
|
+
return { ...buyerSignals };
|
|
69
|
+
}
|
|
70
|
+
export function updateFromOperation(intent, scenario, outcome, errorCode, referencedObjects) {
|
|
71
|
+
try {
|
|
72
|
+
totalCount++;
|
|
73
|
+
if (outcome === "success")
|
|
74
|
+
successCount++;
|
|
75
|
+
if (scenario) {
|
|
76
|
+
scenarioCounts.set(scenario, (scenarioCounts.get(scenario) ?? 0) + 1);
|
|
77
|
+
}
|
|
78
|
+
if (outcome !== "success" && errorCode) {
|
|
79
|
+
pitfallCounts.set(errorCode, (pitfallCounts.get(errorCode) ?? 0) + 1);
|
|
80
|
+
}
|
|
81
|
+
for (const obj of referencedObjects) {
|
|
82
|
+
objectRefs.set(obj, (objectRefs.get(obj) ?? 0) + 1);
|
|
83
|
+
}
|
|
84
|
+
currentProfile = recomputeProfile();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function recomputeProfile() {
|
|
90
|
+
const total = totalCount;
|
|
91
|
+
const successRate = total > 0 ? successCount / total : 1.0;
|
|
92
|
+
let tier = "novice";
|
|
93
|
+
if (total >= 50 && successRate >= 0.9)
|
|
94
|
+
tier = "expert";
|
|
95
|
+
else if (total >= 10 && successRate >= 0.7)
|
|
96
|
+
tier = "advanced";
|
|
97
|
+
const topScenarios = Array.from(scenarioCounts.entries())
|
|
98
|
+
.sort((a, b) => b[1] - a[1])
|
|
99
|
+
.slice(0, 3)
|
|
100
|
+
.map(([s]) => s);
|
|
101
|
+
let riskAppetite = "balanced";
|
|
102
|
+
if (total > 20 && successRate < 0.6)
|
|
103
|
+
riskAppetite = "aggressive";
|
|
104
|
+
else if (total > 20 && successRate > 0.95)
|
|
105
|
+
riskAppetite = "conservative";
|
|
106
|
+
const topPitfalls = Array.from(pitfallCounts.entries())
|
|
107
|
+
.filter(([, count]) => count >= 2)
|
|
108
|
+
.sort((a, b) => b[1] - a[1])
|
|
109
|
+
.slice(0, 3)
|
|
110
|
+
.map(([code]) => code);
|
|
111
|
+
const topObjects = Array.from(objectRefs.entries())
|
|
112
|
+
.filter(([, count]) => count >= 2)
|
|
113
|
+
.sort((a, b) => b[1] - a[1])
|
|
114
|
+
.slice(0, 5)
|
|
115
|
+
.map(([obj]) => obj);
|
|
116
|
+
let preferredConfirmation = "standard";
|
|
117
|
+
if (tier === "expert")
|
|
118
|
+
preferredConfirmation = "minimal";
|
|
119
|
+
else if (tier === "novice")
|
|
120
|
+
preferredConfirmation = "verbose";
|
|
121
|
+
return {
|
|
122
|
+
expertise_tier: tier,
|
|
123
|
+
preferred_industries: topScenarios,
|
|
124
|
+
risk_appetite: riskAppetite,
|
|
125
|
+
frequent_pitfalls: topPitfalls,
|
|
126
|
+
reused_objects: topObjects,
|
|
127
|
+
preferred_confirmation: preferredConfirmation,
|
|
128
|
+
total_operations: total,
|
|
129
|
+
success_rate: successRate,
|
|
130
|
+
last_updated: Date.now(),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export function resetProfile() {
|
|
134
|
+
currentProfile = {
|
|
135
|
+
expertise_tier: "novice",
|
|
136
|
+
preferred_industries: [],
|
|
137
|
+
risk_appetite: "balanced",
|
|
138
|
+
frequent_pitfalls: [],
|
|
139
|
+
reused_objects: [],
|
|
140
|
+
preferred_confirmation: "verbose",
|
|
141
|
+
total_operations: 0,
|
|
142
|
+
success_rate: 1.0,
|
|
143
|
+
last_updated: 0,
|
|
144
|
+
};
|
|
145
|
+
scenarioCounts = new Map();
|
|
146
|
+
pitfallCounts = new Map();
|
|
147
|
+
objectRefs = new Map();
|
|
148
|
+
successCount = 0;
|
|
149
|
+
totalCount = 0;
|
|
150
|
+
buyerSignals = {
|
|
151
|
+
purchase_count: 0,
|
|
152
|
+
avg_purchase_price_ratio: 1.0,
|
|
153
|
+
discount_usage_count: 0,
|
|
154
|
+
referral_usage_count: 0,
|
|
155
|
+
dispute_count: 0,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
export function getProfileStats() {
|
|
159
|
+
return {
|
|
160
|
+
total_operations: totalCount,
|
|
161
|
+
success_rate: totalCount > 0 ? successCount / totalCount : 1.0,
|
|
162
|
+
top_scenarios: Array.from(scenarioCounts.entries())
|
|
163
|
+
.sort((a, b) => b[1] - a[1])
|
|
164
|
+
.slice(0, 5)
|
|
165
|
+
.map(([scenario, count]) => ({ scenario, count })),
|
|
166
|
+
top_pitfalls: Array.from(pitfallCounts.entries())
|
|
167
|
+
.sort((a, b) => b[1] - a[1])
|
|
168
|
+
.slice(0, 5)
|
|
169
|
+
.map(([error_code, count]) => ({ error_code, count })),
|
|
170
|
+
};
|
|
171
|
+
}
|