@elizaos/plugin-training 2.0.3-beta.6 → 2.0.3-beta.7
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/backends/native.d.ts +96 -0
- package/dist/backends/native.d.ts.map +1 -0
- package/dist/backends/native.js +308 -0
- package/dist/backends/native.js.map +1 -0
- package/dist/cli/train.d.ts +22 -0
- package/dist/cli/train.d.ts.map +1 -0
- package/dist/cli/train.js +219 -0
- package/dist/cli/train.js.map +1 -0
- package/dist/core/action-benchmark-runner.d.ts +55 -0
- package/dist/core/action-benchmark-runner.d.ts.map +1 -0
- package/dist/core/action-benchmark-runner.js +341 -0
- package/dist/core/action-benchmark-runner.js.map +1 -0
- package/dist/core/artifact-store.d.ts +72 -0
- package/dist/core/artifact-store.d.ts.map +1 -0
- package/dist/core/artifact-store.js +50 -0
- package/dist/core/artifact-store.js.map +1 -0
- package/dist/core/benchmark-matrix-artifact.d.ts +102 -0
- package/dist/core/benchmark-matrix-artifact.d.ts.map +1 -0
- package/dist/core/benchmark-matrix-artifact.js +381 -0
- package/dist/core/benchmark-matrix-artifact.js.map +1 -0
- package/dist/core/benchmark-vs-cerebras-runner.d.ts +37 -0
- package/dist/core/benchmark-vs-cerebras-runner.d.ts.map +1 -0
- package/dist/core/benchmark-vs-cerebras-runner.js +151 -0
- package/dist/core/benchmark-vs-cerebras-runner.js.map +1 -0
- package/dist/core/cerebras-eval-model.d.ts +54 -0
- package/dist/core/cerebras-eval-model.d.ts.map +1 -0
- package/dist/core/cerebras-eval-model.js +249 -0
- package/dist/core/cerebras-eval-model.js.map +1 -0
- package/dist/core/cli.d.ts +15 -0
- package/dist/core/cli.d.ts.map +1 -0
- package/dist/core/cli.js +1003 -0
- package/dist/core/cli.js.map +1 -0
- package/dist/core/context-audit.d.ts +51 -0
- package/dist/core/context-audit.d.ts.map +1 -0
- package/dist/core/context-audit.js +166 -0
- package/dist/core/context-audit.js.map +1 -0
- package/dist/core/context-catalog.d.ts +47 -0
- package/dist/core/context-catalog.d.ts.map +1 -0
- package/dist/core/context-catalog.js +269 -0
- package/dist/core/context-catalog.js.map +1 -0
- package/dist/core/context-types.d.ts +3 -0
- package/dist/core/context-types.d.ts.map +1 -0
- package/dist/core/context-types.js +18 -0
- package/dist/core/context-types.js.map +1 -0
- package/dist/core/dataset-generator.d.ts +135 -0
- package/dist/core/dataset-generator.d.ts.map +1 -0
- package/dist/core/dataset-generator.js +895 -0
- package/dist/core/dataset-generator.js.map +1 -0
- package/dist/core/eliza1-benchmark-recipe.d.ts +18 -0
- package/dist/core/eliza1-benchmark-recipe.d.ts.map +1 -0
- package/dist/core/eliza1-benchmark-recipe.js +64 -0
- package/dist/core/eliza1-benchmark-recipe.js.map +1 -0
- package/dist/core/eliza1-bundle-stager.d.ts +57 -0
- package/dist/core/eliza1-bundle-stager.d.ts.map +1 -0
- package/dist/core/eliza1-bundle-stager.js +149 -0
- package/dist/core/eliza1-bundle-stager.js.map +1 -0
- package/dist/core/ensure-cron-job.d.ts +53 -0
- package/dist/core/ensure-cron-job.d.ts.map +1 -0
- package/dist/core/ensure-cron-job.js +51 -0
- package/dist/core/ensure-cron-job.js.map +1 -0
- package/dist/core/eval-comparison-artifact.d.ts +72 -0
- package/dist/core/eval-comparison-artifact.d.ts.map +1 -0
- package/dist/core/eval-comparison-artifact.js +281 -0
- package/dist/core/eval-comparison-artifact.js.map +1 -0
- package/dist/core/feed-generation-runner.d.ts +37 -0
- package/dist/core/feed-generation-runner.d.ts.map +1 -0
- package/dist/core/feed-generation-runner.js +232 -0
- package/dist/core/feed-generation-runner.js.map +1 -0
- package/dist/core/html-escape.d.ts +5 -0
- package/dist/core/html-escape.d.ts.map +1 -0
- package/dist/core/html-escape.js +11 -0
- package/dist/core/html-escape.js.map +1 -0
- package/dist/core/huggingface-dataset-ingest.d.ts +52 -0
- package/dist/core/huggingface-dataset-ingest.d.ts.map +1 -0
- package/dist/core/huggingface-dataset-ingest.js +134 -0
- package/dist/core/huggingface-dataset-ingest.js.map +1 -0
- package/dist/core/index.d.ts +29 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +204 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/privacy-filter.d.ts +95 -0
- package/dist/core/privacy-filter.d.ts.map +1 -0
- package/dist/core/privacy-filter.js +324 -0
- package/dist/core/privacy-filter.js.map +1 -0
- package/dist/core/promotion-gate.d.ts +117 -0
- package/dist/core/promotion-gate.d.ts.map +1 -0
- package/dist/core/promotion-gate.js +85 -0
- package/dist/core/promotion-gate.js.map +1 -0
- package/dist/core/promotion-persist.d.ts +116 -0
- package/dist/core/promotion-persist.d.ts.map +1 -0
- package/dist/core/promotion-persist.js +93 -0
- package/dist/core/promotion-persist.js.map +1 -0
- package/dist/core/prompt-compare.d.ts +99 -0
- package/dist/core/prompt-compare.d.ts.map +1 -0
- package/dist/core/prompt-compare.js +210 -0
- package/dist/core/prompt-compare.js.map +1 -0
- package/dist/core/replay-validator.d.ts +136 -0
- package/dist/core/replay-validator.d.ts.map +1 -0
- package/dist/core/replay-validator.js +312 -0
- package/dist/core/replay-validator.js.map +1 -0
- package/dist/core/roleplay-executor.d.ts +123 -0
- package/dist/core/roleplay-executor.d.ts.map +1 -0
- package/dist/core/roleplay-executor.js +675 -0
- package/dist/core/roleplay-executor.js.map +1 -0
- package/dist/core/roleplay-trajectories.d.ts +54 -0
- package/dist/core/roleplay-trajectories.d.ts.map +1 -0
- package/dist/core/roleplay-trajectories.js +88 -0
- package/dist/core/roleplay-trajectories.js.map +1 -0
- package/dist/core/scenario-blueprints.d.ts +62 -0
- package/dist/core/scenario-blueprints.d.ts.map +1 -0
- package/dist/core/scenario-blueprints.js +850 -0
- package/dist/core/scenario-blueprints.js.map +1 -0
- package/dist/core/scenario-runner.d.ts +36 -0
- package/dist/core/scenario-runner.d.ts.map +1 -0
- package/dist/core/scenario-runner.js +216 -0
- package/dist/core/scenario-runner.js.map +1 -0
- package/dist/core/skill-scoring-cron.d.ts +57 -0
- package/dist/core/skill-scoring-cron.d.ts.map +1 -0
- package/dist/core/skill-scoring-cron.js +180 -0
- package/dist/core/skill-scoring-cron.js.map +1 -0
- package/dist/core/test-trajectory-collector.d.ts +37 -0
- package/dist/core/test-trajectory-collector.d.ts.map +1 -0
- package/dist/core/test-trajectory-collector.js +225 -0
- package/dist/core/test-trajectory-collector.js.map +1 -0
- package/dist/core/track-c-queue-task.d.ts +37 -0
- package/dist/core/track-c-queue-task.d.ts.map +1 -0
- package/dist/core/track-c-queue-task.js +104 -0
- package/dist/core/track-c-queue-task.js.map +1 -0
- package/dist/core/training-analysis-index.d.ts +104 -0
- package/dist/core/training-analysis-index.d.ts.map +1 -0
- package/dist/core/training-analysis-index.js +3297 -0
- package/dist/core/training-analysis-index.js.map +1 -0
- package/dist/core/training-collection-runner.d.ts +508 -0
- package/dist/core/training-collection-runner.d.ts.map +1 -0
- package/dist/core/training-collection-runner.js +2299 -0
- package/dist/core/training-collection-runner.js.map +1 -0
- package/dist/core/training-config.d.ts +52 -0
- package/dist/core/training-config.d.ts.map +1 -0
- package/dist/core/training-config.js +117 -0
- package/dist/core/training-config.js.map +1 -0
- package/dist/core/training-orchestrator.d.ts +112 -0
- package/dist/core/training-orchestrator.d.ts.map +1 -0
- package/dist/core/training-orchestrator.js +729 -0
- package/dist/core/training-orchestrator.js.map +1 -0
- package/dist/core/training-readiness-report.d.ts +52 -0
- package/dist/core/training-readiness-report.d.ts.map +1 -0
- package/dist/core/training-readiness-report.js +765 -0
- package/dist/core/training-readiness-report.js.map +1 -0
- package/dist/core/trajectory-consumer.d.ts +15 -0
- package/dist/core/trajectory-consumer.d.ts.map +1 -0
- package/dist/core/trajectory-consumer.js +61 -0
- package/dist/core/trajectory-consumer.js.map +1 -0
- package/dist/core/trajectory-export-bundle.d.ts +95 -0
- package/dist/core/trajectory-export-bundle.d.ts.map +1 -0
- package/dist/core/trajectory-export-bundle.js +561 -0
- package/dist/core/trajectory-export-bundle.js.map +1 -0
- package/dist/core/trajectory-export-cron.d.ts +57 -0
- package/dist/core/trajectory-export-cron.d.ts.map +1 -0
- package/dist/core/trajectory-export-cron.js +170 -0
- package/dist/core/trajectory-export-cron.js.map +1 -0
- package/dist/core/trajectory-hf-upload.d.ts +50 -0
- package/dist/core/trajectory-hf-upload.d.ts.map +1 -0
- package/dist/core/trajectory-hf-upload.js +111 -0
- package/dist/core/trajectory-hf-upload.js.map +1 -0
- package/dist/core/trajectory-task-datasets.d.ts +62 -0
- package/dist/core/trajectory-task-datasets.d.ts.map +1 -0
- package/dist/core/trajectory-task-datasets.js +427 -0
- package/dist/core/trajectory-task-datasets.js.map +1 -0
- package/dist/core/wait-for-service.d.ts +25 -0
- package/dist/core/wait-for-service.d.ts.map +1 -0
- package/dist/core/wait-for-service.js +19 -0
- package/dist/core/wait-for-service.js.map +1 -0
- package/dist/core/workspace-runtime.d.ts +4 -0
- package/dist/core/workspace-runtime.d.ts.map +1 -0
- package/dist/core/workspace-runtime.js +25 -0
- package/dist/core/workspace-runtime.js.map +1 -0
- package/dist/dspy/artifact.d.ts +54 -0
- package/dist/dspy/artifact.d.ts.map +1 -0
- package/dist/dspy/artifact.js +61 -0
- package/dist/dspy/artifact.js.map +1 -0
- package/dist/dspy/chain-of-thought.d.ts +27 -0
- package/dist/dspy/chain-of-thought.d.ts.map +1 -0
- package/dist/dspy/chain-of-thought.js +43 -0
- package/dist/dspy/chain-of-thought.js.map +1 -0
- package/dist/dspy/examples.d.ts +72 -0
- package/dist/dspy/examples.d.ts.map +1 -0
- package/dist/dspy/examples.js +105 -0
- package/dist/dspy/examples.js.map +1 -0
- package/dist/dspy/index.d.ts +15 -0
- package/dist/dspy/index.d.ts.map +1 -0
- package/dist/dspy/index.js +40 -0
- package/dist/dspy/index.js.map +1 -0
- package/dist/dspy/lm-adapter.d.ts +100 -0
- package/dist/dspy/lm-adapter.d.ts.map +1 -0
- package/dist/dspy/lm-adapter.js +81 -0
- package/dist/dspy/lm-adapter.js.map +1 -0
- package/dist/dspy/optimizers/dspy-bootstrap-fewshot.d.ts +23 -0
- package/dist/dspy/optimizers/dspy-bootstrap-fewshot.d.ts.map +1 -0
- package/dist/dspy/optimizers/dspy-bootstrap-fewshot.js +85 -0
- package/dist/dspy/optimizers/dspy-bootstrap-fewshot.js.map +1 -0
- package/dist/dspy/optimizers/dspy-copro.d.ts +29 -0
- package/dist/dspy/optimizers/dspy-copro.d.ts.map +1 -0
- package/dist/dspy/optimizers/dspy-copro.js +141 -0
- package/dist/dspy/optimizers/dspy-copro.js.map +1 -0
- package/dist/dspy/optimizers/dspy-mipro.d.ts +37 -0
- package/dist/dspy/optimizers/dspy-mipro.d.ts.map +1 -0
- package/dist/dspy/optimizers/dspy-mipro.js +194 -0
- package/dist/dspy/optimizers/dspy-mipro.js.map +1 -0
- package/dist/dspy/optimizers/index.d.ts +5 -0
- package/dist/dspy/optimizers/index.d.ts.map +1 -0
- package/dist/dspy/optimizers/index.js +11 -0
- package/dist/dspy/optimizers/index.js.map +1 -0
- package/dist/dspy/optimizers/types.d.ts +39 -0
- package/dist/dspy/optimizers/types.d.ts.map +1 -0
- package/dist/dspy/optimizers/types.js +1 -0
- package/dist/dspy/optimizers/types.js.map +1 -0
- package/dist/dspy/predict.d.ts +49 -0
- package/dist/dspy/predict.d.ts.map +1 -0
- package/dist/dspy/predict.js +73 -0
- package/dist/dspy/predict.js.map +1 -0
- package/dist/dspy/signature.d.ts +88 -0
- package/dist/dspy/signature.d.ts.map +1 -0
- package/dist/dspy/signature.js +205 -0
- package/dist/dspy/signature.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/optimizers/bootstrap-fewshot.d.ts +42 -0
- package/dist/optimizers/bootstrap-fewshot.d.ts.map +1 -0
- package/dist/optimizers/bootstrap-fewshot.js +92 -0
- package/dist/optimizers/bootstrap-fewshot.js.map +1 -0
- package/dist/optimizers/gepa.d.ts +63 -0
- package/dist/optimizers/gepa.d.ts.map +1 -0
- package/dist/optimizers/gepa.js +232 -0
- package/dist/optimizers/gepa.js.map +1 -0
- package/dist/optimizers/index.d.ts +7 -0
- package/dist/optimizers/index.d.ts.map +1 -0
- package/dist/optimizers/index.js +51 -0
- package/dist/optimizers/index.js.map +1 -0
- package/dist/optimizers/instruction-search.d.ts +39 -0
- package/dist/optimizers/instruction-search.d.ts.map +1 -0
- package/dist/optimizers/instruction-search.js +108 -0
- package/dist/optimizers/instruction-search.js.map +1 -0
- package/dist/optimizers/prompt-evolution.d.ts +39 -0
- package/dist/optimizers/prompt-evolution.d.ts.map +1 -0
- package/dist/optimizers/prompt-evolution.js +101 -0
- package/dist/optimizers/prompt-evolution.js.map +1 -0
- package/dist/optimizers/scoring.d.ts +139 -0
- package/dist/optimizers/scoring.d.ts.map +1 -0
- package/dist/optimizers/scoring.js +299 -0
- package/dist/optimizers/scoring.js.map +1 -0
- package/dist/optimizers/types.d.ts +105 -0
- package/dist/optimizers/types.d.ts.map +1 -0
- package/dist/optimizers/types.js +1 -0
- package/dist/optimizers/types.js.map +1 -0
- package/dist/register-runtime.d.ts +3 -0
- package/dist/register-runtime.d.ts.map +1 -0
- package/dist/register-runtime.js +60 -0
- package/dist/register-runtime.js.map +1 -0
- package/dist/register-terminal-view.d.ts +15 -0
- package/dist/register-terminal-view.d.ts.map +1 -0
- package/dist/register-terminal-view.js +31 -0
- package/dist/register-terminal-view.js.map +1 -0
- package/dist/routes/experience-routes.d.ts +21 -0
- package/dist/routes/experience-routes.d.ts.map +1 -0
- package/dist/routes/experience-routes.js +513 -0
- package/dist/routes/experience-routes.js.map +1 -0
- package/dist/routes/index.d.ts +5 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +17 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/training-routes.d.ts +10 -0
- package/dist/routes/training-routes.d.ts.map +1 -0
- package/dist/routes/training-routes.js +1239 -0
- package/dist/routes/training-routes.js.map +1 -0
- package/dist/routes/training-vast-routes.d.ts +35 -0
- package/dist/routes/training-vast-routes.d.ts.map +1 -0
- package/dist/routes/training-vast-routes.js +249 -0
- package/dist/routes/training-vast-routes.js.map +1 -0
- package/dist/routes/trajectory-routes.d.ts +19 -0
- package/dist/routes/trajectory-routes.d.ts.map +1 -0
- package/dist/routes/trajectory-routes.js +1122 -0
- package/dist/routes/trajectory-routes.js.map +1 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +63 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/training-backend-check.d.ts +8 -0
- package/dist/services/training-backend-check.d.ts.map +1 -0
- package/dist/services/training-backend-check.js +31 -0
- package/dist/services/training-backend-check.js.map +1 -0
- package/dist/services/training-service-like.d.ts +40 -0
- package/dist/services/training-service-like.d.ts.map +1 -0
- package/dist/services/training-service-like.js +1 -0
- package/dist/services/training-service-like.js.map +1 -0
- package/dist/services/training-service-registry.d.ts +4 -0
- package/dist/services/training-service-registry.d.ts.map +1 -0
- package/dist/services/training-service-registry.js +12 -0
- package/dist/services/training-service-registry.js.map +1 -0
- package/dist/services/training-service.d.ts +59 -0
- package/dist/services/training-service.d.ts.map +1 -0
- package/dist/services/training-service.js +154 -0
- package/dist/services/training-service.js.map +1 -0
- package/dist/services/training-trigger.d.ts +177 -0
- package/dist/services/training-trigger.d.ts.map +1 -0
- package/dist/services/training-trigger.js +300 -0
- package/dist/services/training-trigger.js.map +1 -0
- package/dist/services/training-vast-service.d.ts +149 -0
- package/dist/services/training-vast-service.d.ts.map +1 -0
- package/dist/services/training-vast-service.js +648 -0
- package/dist/services/training-vast-service.js.map +1 -0
- package/dist/services/vast-inference-stats.d.ts +37 -0
- package/dist/services/vast-inference-stats.d.ts.map +1 -0
- package/dist/services/vast-inference-stats.js +81 -0
- package/dist/services/vast-inference-stats.js.map +1 -0
- package/dist/services/vast-job-store.d.ts +74 -0
- package/dist/services/vast-job-store.d.ts.map +1 -0
- package/dist/services/vast-job-store.js +194 -0
- package/dist/services/vast-job-store.js.map +1 -0
- package/dist/services/vast-subprocess.d.ts +27 -0
- package/dist/services/vast-subprocess.d.ts.map +1 -0
- package/dist/services/vast-subprocess.js +78 -0
- package/dist/services/vast-subprocess.js.map +1 -0
- package/dist/setup-routes.d.ts +17 -0
- package/dist/setup-routes.d.ts.map +1 -0
- package/dist/setup-routes.js +319 -0
- package/dist/setup-routes.js.map +1 -0
- package/dist/ui/FineTuningSpatialView.d.ts +49 -0
- package/dist/ui/FineTuningSpatialView.d.ts.map +1 -0
- package/dist/ui/FineTuningSpatialView.js +154 -0
- package/dist/ui/FineTuningSpatialView.js.map +1 -0
- package/dist/ui/FineTuningView.d.ts +7 -0
- package/dist/ui/FineTuningView.d.ts.map +1 -0
- package/dist/ui/FineTuningView.helpers.d.ts +17 -0
- package/dist/ui/FineTuningView.helpers.d.ts.map +1 -0
- package/dist/ui/FineTuningView.helpers.js +30 -0
- package/dist/ui/FineTuningView.helpers.js.map +1 -0
- package/dist/ui/FineTuningView.interact.d.ts +2 -0
- package/dist/ui/FineTuningView.interact.d.ts.map +1 -0
- package/dist/ui/FineTuningView.interact.js +300 -0
- package/dist/ui/FineTuningView.interact.js.map +1 -0
- package/dist/ui/FineTuningView.js +4653 -0
- package/dist/ui/FineTuningView.js.map +1 -0
- package/dist/ui/fine-tuning-panels.d.ts +100 -0
- package/dist/ui/fine-tuning-panels.d.ts.map +1 -0
- package/dist/ui/fine-tuning-panels.helpers.d.ts +19 -0
- package/dist/ui/fine-tuning-panels.helpers.d.ts.map +1 -0
- package/dist/ui/fine-tuning-panels.helpers.js +77 -0
- package/dist/ui/fine-tuning-panels.helpers.js.map +1 -0
- package/dist/ui/fine-tuning-panels.js +928 -0
- package/dist/ui/fine-tuning-panels.js.map +1 -0
- package/dist/ui/index.d.ts +5 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +5 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/training-view-bundle.d.ts +3 -0
- package/dist/ui/training-view-bundle.d.ts.map +1 -0
- package/dist/ui/training-view-bundle.js +7 -0
- package/dist/ui/training-view-bundle.js.map +1 -0
- package/dist/views/bundle.js +5312 -0
- package/dist/views/bundle.js.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
exportTrajectoryTaskDatasets
|
|
6
|
+
} from "./trajectory-task-datasets.js";
|
|
7
|
+
const GROUP_CHANNEL = "GROUP";
|
|
8
|
+
function deterministicUuid(seed) {
|
|
9
|
+
const hex = createHash("sha1").update(seed).digest("hex").slice(0, 32);
|
|
10
|
+
return [
|
|
11
|
+
hex.slice(0, 8),
|
|
12
|
+
hex.slice(8, 12),
|
|
13
|
+
hex.slice(12, 16),
|
|
14
|
+
hex.slice(16, 20),
|
|
15
|
+
hex.slice(20, 32)
|
|
16
|
+
].join("-");
|
|
17
|
+
}
|
|
18
|
+
function isRecord(value) {
|
|
19
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
function parseDelimitedList(value) {
|
|
22
|
+
return value.split(",").map((entry) => entry.trim()).filter(
|
|
23
|
+
(entry, index, entries) => entry.length > 0 && entries.indexOf(entry) === index
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function stripOutputFences(response) {
|
|
27
|
+
return response.trim().replace(/^```[a-z0-9_-]*\s*/i, "").replace(/\s*```$/i, "").trim();
|
|
28
|
+
}
|
|
29
|
+
function parseJsonObject(response) {
|
|
30
|
+
const trimmed = stripOutputFences(response);
|
|
31
|
+
if (!trimmed.startsWith("{")) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const parsed = JSON.parse(trimmed);
|
|
36
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function getMessageHandlerCandidate(parsed) {
|
|
42
|
+
const nested = parsed.messageHandler;
|
|
43
|
+
if (isRecord(nested)) {
|
|
44
|
+
return nested;
|
|
45
|
+
}
|
|
46
|
+
if (typeof parsed.action === "string") {
|
|
47
|
+
return parsed;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function readLegacyField(response, fieldName) {
|
|
52
|
+
const lineMatch = new RegExp(`(^|\\n)${fieldName}:\\s*([^\\n]+)`, "i").exec(
|
|
53
|
+
response
|
|
54
|
+
);
|
|
55
|
+
if (lineMatch?.[2]) {
|
|
56
|
+
const value = lineMatch[2].trim();
|
|
57
|
+
return value.length > 0 ? value : void 0;
|
|
58
|
+
}
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
function parseRoutingDecision(response) {
|
|
62
|
+
const parsed = parseJsonObject(response);
|
|
63
|
+
const candidate = parsed ? getMessageHandlerCandidate(parsed) : null;
|
|
64
|
+
const rawAction = typeof candidate?.action === "string" ? candidate.action : readLegacyField(response, "action");
|
|
65
|
+
const decision = rawAction?.toUpperCase();
|
|
66
|
+
const contexts = Array.isArray(candidate?.contexts) ? candidate.contexts.filter(
|
|
67
|
+
(context) => typeof context === "string" && context.trim().length > 0
|
|
68
|
+
) : [];
|
|
69
|
+
const primaryContext = contexts[0] ?? readLegacyField(response, "primaryContext");
|
|
70
|
+
const secondaryContexts = contexts.length > 1 ? contexts.slice(1) : parseDelimitedList(
|
|
71
|
+
readLegacyField(response, "secondaryContexts") ?? ""
|
|
72
|
+
);
|
|
73
|
+
return {
|
|
74
|
+
decision: decision === "RESPOND" || decision === "IGNORE" || decision === "STOP" ? decision : void 0,
|
|
75
|
+
primaryContext,
|
|
76
|
+
secondaryContexts
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function collectRuntimeCandidates(runtime) {
|
|
80
|
+
const candidates = [];
|
|
81
|
+
const seen = /* @__PURE__ */ new Set();
|
|
82
|
+
const push = (candidate) => {
|
|
83
|
+
if (!candidate || seen.has(candidate)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
seen.add(candidate);
|
|
87
|
+
candidates.push(candidate);
|
|
88
|
+
};
|
|
89
|
+
if (typeof runtime.getServicesByType === "function") {
|
|
90
|
+
const value = runtime.getServicesByType("trajectories");
|
|
91
|
+
if (Array.isArray(value)) {
|
|
92
|
+
for (const entry of value) {
|
|
93
|
+
push(entry);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
push(value);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (typeof runtime.getService === "function") {
|
|
100
|
+
push(runtime.getService("trajectories"));
|
|
101
|
+
}
|
|
102
|
+
return candidates;
|
|
103
|
+
}
|
|
104
|
+
function getTrajectoryLogger(runtime) {
|
|
105
|
+
for (const candidate of collectRuntimeCandidates(runtime)) {
|
|
106
|
+
if (candidate && typeof candidate === "object" && typeof candidate.getTrajectoryDetail === "function") {
|
|
107
|
+
return candidate;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
async function waitForTrajectoryDetail(logger, trajectoryId) {
|
|
113
|
+
if (!logger?.getTrajectoryDetail) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
117
|
+
const detail = await logger.getTrajectoryDetail(trajectoryId);
|
|
118
|
+
if (detail) {
|
|
119
|
+
return detail;
|
|
120
|
+
}
|
|
121
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
function normalizeActionName(value) {
|
|
126
|
+
if (typeof value !== "string") {
|
|
127
|
+
return "";
|
|
128
|
+
}
|
|
129
|
+
return value.trim().toUpperCase();
|
|
130
|
+
}
|
|
131
|
+
function collectActionNamesFromContent(content) {
|
|
132
|
+
if (!content?.actions) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
return content.actions.map((action) => normalizeActionName(action)).filter(
|
|
136
|
+
(action, index, actions) => action.length > 0 && actions.indexOf(action) === index
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function collectExecutedActionNames(runtime, messageId) {
|
|
140
|
+
return runtime.getActionResults(messageId).map((result) => {
|
|
141
|
+
if (typeof result === "string") {
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
const record = isRecord(result) ? result : null;
|
|
145
|
+
if (!record) {
|
|
146
|
+
return "";
|
|
147
|
+
}
|
|
148
|
+
if (typeof record.actionName === "string") {
|
|
149
|
+
return record.actionName;
|
|
150
|
+
}
|
|
151
|
+
const data = isRecord(record.data) ? record.data : null;
|
|
152
|
+
return typeof data?.actionName === "string" ? data.actionName : "";
|
|
153
|
+
}).map((action) => normalizeActionName(action)).filter(
|
|
154
|
+
(action, index, actions) => action.length > 0 && actions.indexOf(action) === index
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function resolveActualDecision(args) {
|
|
158
|
+
const callbackActions = args.callbackContents.flatMap(
|
|
159
|
+
(content) => collectActionNamesFromContent(content)
|
|
160
|
+
);
|
|
161
|
+
if (callbackActions.includes("STOP")) {
|
|
162
|
+
return "STOP";
|
|
163
|
+
}
|
|
164
|
+
if (callbackActions.includes("IGNORE")) {
|
|
165
|
+
return "IGNORE";
|
|
166
|
+
}
|
|
167
|
+
const responseActions = collectActionNamesFromContent(args.responseContent);
|
|
168
|
+
if (responseActions.includes("STOP")) {
|
|
169
|
+
return "STOP";
|
|
170
|
+
}
|
|
171
|
+
if (responseActions.includes("IGNORE") && !args.didRespond) {
|
|
172
|
+
return "IGNORE";
|
|
173
|
+
}
|
|
174
|
+
if (args.shouldRespondDecision) {
|
|
175
|
+
return args.shouldRespondDecision;
|
|
176
|
+
}
|
|
177
|
+
return args.didRespond ? "RESPOND" : "IGNORE";
|
|
178
|
+
}
|
|
179
|
+
function secondaryContextsEqual(expected, actual) {
|
|
180
|
+
const normalizedExpected = [
|
|
181
|
+
...new Set(expected.map((value) => value.trim().toLowerCase()))
|
|
182
|
+
].filter(Boolean).sort();
|
|
183
|
+
const normalizedActual = [
|
|
184
|
+
...new Set(actual.map((value) => value.trim().toLowerCase()))
|
|
185
|
+
].filter(Boolean).sort();
|
|
186
|
+
return JSON.stringify(normalizedExpected) === JSON.stringify(normalizedActual);
|
|
187
|
+
}
|
|
188
|
+
function buildEmptyBucketReport() {
|
|
189
|
+
return {
|
|
190
|
+
totalEpisodes: 0,
|
|
191
|
+
decisionMatches: 0,
|
|
192
|
+
routingMatches: 0,
|
|
193
|
+
primaryContextMatches: 0,
|
|
194
|
+
secondaryContextExactMatches: 0,
|
|
195
|
+
actionRelevantEpisodes: 0,
|
|
196
|
+
actionMatches: 0,
|
|
197
|
+
selectedActionMatches: 0,
|
|
198
|
+
executedActionMatches: 0,
|
|
199
|
+
decisionAccuracy: 0,
|
|
200
|
+
routingAccuracy: 0,
|
|
201
|
+
primaryContextAccuracy: 0,
|
|
202
|
+
secondaryContextExactAccuracy: 0,
|
|
203
|
+
actionAccuracy: 0,
|
|
204
|
+
selectedActionAccuracy: 0,
|
|
205
|
+
executedActionAccuracy: 0
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function finalizeBucketReport(bucket) {
|
|
209
|
+
return {
|
|
210
|
+
...bucket,
|
|
211
|
+
decisionAccuracy: bucket.decisionMatches / (bucket.totalEpisodes || 1),
|
|
212
|
+
routingAccuracy: bucket.routingMatches / (bucket.totalEpisodes || 1),
|
|
213
|
+
primaryContextAccuracy: bucket.primaryContextMatches / (bucket.totalEpisodes || 1),
|
|
214
|
+
secondaryContextExactAccuracy: bucket.secondaryContextExactMatches / (bucket.totalEpisodes || 1),
|
|
215
|
+
actionAccuracy: bucket.actionMatches / (bucket.actionRelevantEpisodes || 1),
|
|
216
|
+
selectedActionAccuracy: bucket.selectedActionMatches / (bucket.actionRelevantEpisodes || 1),
|
|
217
|
+
executedActionAccuracy: bucket.executedActionMatches / (bucket.actionRelevantEpisodes || 1)
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function updateBucketReport(bucket, execution) {
|
|
221
|
+
bucket.totalEpisodes += 1;
|
|
222
|
+
if (execution.decisionMatch) {
|
|
223
|
+
bucket.decisionMatches += 1;
|
|
224
|
+
}
|
|
225
|
+
if (execution.routingMatch) {
|
|
226
|
+
bucket.routingMatches += 1;
|
|
227
|
+
}
|
|
228
|
+
if (execution.primaryContextMatch) {
|
|
229
|
+
bucket.primaryContextMatches += 1;
|
|
230
|
+
}
|
|
231
|
+
if (execution.secondaryContextExactMatch) {
|
|
232
|
+
bucket.secondaryContextExactMatches += 1;
|
|
233
|
+
}
|
|
234
|
+
if (execution.expectedAction) {
|
|
235
|
+
bucket.actionRelevantEpisodes += 1;
|
|
236
|
+
if (execution.actionMatch) {
|
|
237
|
+
bucket.actionMatches += 1;
|
|
238
|
+
}
|
|
239
|
+
if (execution.selectedActionMatch) {
|
|
240
|
+
bucket.selectedActionMatches += 1;
|
|
241
|
+
}
|
|
242
|
+
if (execution.executedActionMatch) {
|
|
243
|
+
bucket.executedActionMatches += 1;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function createDecisionConfusionMatrix() {
|
|
248
|
+
return {
|
|
249
|
+
RESPOND: { RESPOND: 0, IGNORE: 0, STOP: 0 },
|
|
250
|
+
IGNORE: { RESPOND: 0, IGNORE: 0, STOP: 0 },
|
|
251
|
+
STOP: { RESPOND: 0, IGNORE: 0, STOP: 0 }
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function resolveMessageRoutingFallback(message) {
|
|
255
|
+
const metadata = message.content.metadata && typeof message.content.metadata === "object" ? message.content.metadata : {};
|
|
256
|
+
const responseContext = metadata.__responseContext && typeof metadata.__responseContext === "object" ? metadata.__responseContext : {};
|
|
257
|
+
const secondaryContexts = Array.isArray(responseContext.secondaryContexts) ? responseContext.secondaryContexts.filter(
|
|
258
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
259
|
+
) : parseDelimitedList(String(responseContext.secondaryContexts ?? ""));
|
|
260
|
+
return {
|
|
261
|
+
primaryContext: typeof responseContext.primaryContext === "string" ? responseContext.primaryContext : void 0,
|
|
262
|
+
secondaryContexts
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function buildParticipantId(episodeId, speaker) {
|
|
266
|
+
return deterministicUuid(`roleplay-${episodeId}-${speaker.toLowerCase()}`);
|
|
267
|
+
}
|
|
268
|
+
function buildRoomIds(episodeId) {
|
|
269
|
+
return {
|
|
270
|
+
roomId: deterministicUuid(`roleplay-room-${episodeId}`),
|
|
271
|
+
worldId: deterministicUuid(`roleplay-world-${episodeId}`),
|
|
272
|
+
messageServerId: deterministicUuid(`roleplay-server-${episodeId}`)
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async function seedTurnMemory(runtime, episode, turn, roomIds) {
|
|
276
|
+
const entityId = turn.role === "assistant" ? runtime.agentId : buildParticipantId(episode.id, turn.speaker);
|
|
277
|
+
await runtime.createMemory(
|
|
278
|
+
{
|
|
279
|
+
id: deterministicUuid(`roleplay-seed-${episode.id}-${turn.id}`),
|
|
280
|
+
entityId,
|
|
281
|
+
agentId: runtime.agentId,
|
|
282
|
+
roomId: roomIds.roomId,
|
|
283
|
+
createdAt: Date.now(),
|
|
284
|
+
content: {
|
|
285
|
+
text: turn.content,
|
|
286
|
+
source: episode.platform,
|
|
287
|
+
channelType: GROUP_CHANNEL,
|
|
288
|
+
metadata: {
|
|
289
|
+
entityName: turn.speaker
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
"messages"
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
async function ensureRoleplayConnections(runtime, episode, roomIds) {
|
|
297
|
+
if (typeof runtime.ensureConnection !== "function") {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const participants = [
|
|
301
|
+
...new Set(
|
|
302
|
+
episode.turns.filter((turn) => turn.role === "participant").map((turn) => turn.speaker)
|
|
303
|
+
)
|
|
304
|
+
];
|
|
305
|
+
for (const speaker of participants) {
|
|
306
|
+
const entityId = buildParticipantId(episode.id, speaker);
|
|
307
|
+
await runtime.ensureConnection({
|
|
308
|
+
entityId,
|
|
309
|
+
roomId: roomIds.roomId,
|
|
310
|
+
worldId: roomIds.worldId,
|
|
311
|
+
userName: speaker,
|
|
312
|
+
source: episode.platform,
|
|
313
|
+
channelId: `roleplay-${episode.id}`,
|
|
314
|
+
type: GROUP_CHANNEL,
|
|
315
|
+
messageServerId: roomIds.messageServerId,
|
|
316
|
+
metadata: {
|
|
317
|
+
ownership: {
|
|
318
|
+
ownerId: entityId
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async function resolveRuntime(runtime) {
|
|
325
|
+
if (runtime) {
|
|
326
|
+
return runtime;
|
|
327
|
+
}
|
|
328
|
+
const { bootElizaRuntime } = await import("@elizaos/agent");
|
|
329
|
+
return await bootElizaRuntime();
|
|
330
|
+
}
|
|
331
|
+
async function executeRoleplayEpisode(episode, options = {}) {
|
|
332
|
+
const runtime = await resolveRuntime(options.runtime);
|
|
333
|
+
const roomIds = buildRoomIds(episode.id);
|
|
334
|
+
const logger = getTrajectoryLogger(runtime);
|
|
335
|
+
const turnExecutions = [];
|
|
336
|
+
await ensureRoleplayConnections(runtime, episode, roomIds);
|
|
337
|
+
for (const turn of episode.turns) {
|
|
338
|
+
if (turn.role === "assistant") {
|
|
339
|
+
await seedTurnMemory(runtime, episode, turn, roomIds);
|
|
340
|
+
turnExecutions.push({
|
|
341
|
+
turnId: turn.id,
|
|
342
|
+
speaker: turn.speaker,
|
|
343
|
+
role: turn.role,
|
|
344
|
+
isEvaluationTarget: turn.isEvaluationTarget,
|
|
345
|
+
actualSecondaryContexts: [],
|
|
346
|
+
selectedActions: [],
|
|
347
|
+
executedActions: [],
|
|
348
|
+
responseText: turn.content,
|
|
349
|
+
callbackTexts: [],
|
|
350
|
+
warnings: []
|
|
351
|
+
});
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (!turn.isEvaluationTarget && !options.executeAllParticipantTurns) {
|
|
355
|
+
await seedTurnMemory(runtime, episode, turn, roomIds);
|
|
356
|
+
turnExecutions.push({
|
|
357
|
+
turnId: turn.id,
|
|
358
|
+
speaker: turn.speaker,
|
|
359
|
+
role: turn.role,
|
|
360
|
+
isEvaluationTarget: false,
|
|
361
|
+
actualSecondaryContexts: [],
|
|
362
|
+
selectedActions: [],
|
|
363
|
+
executedActions: [],
|
|
364
|
+
responseText: "",
|
|
365
|
+
callbackTexts: [],
|
|
366
|
+
warnings: []
|
|
367
|
+
});
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
const trajectoryId = deterministicUuid(
|
|
371
|
+
`roleplay-trajectory-${episode.id}-${turn.id}`
|
|
372
|
+
);
|
|
373
|
+
const message = {
|
|
374
|
+
id: deterministicUuid(`roleplay-message-${episode.id}-${turn.id}`),
|
|
375
|
+
entityId: buildParticipantId(episode.id, turn.speaker),
|
|
376
|
+
roomId: roomIds.roomId,
|
|
377
|
+
agentId: runtime.agentId,
|
|
378
|
+
createdAt: Date.now(),
|
|
379
|
+
content: {
|
|
380
|
+
text: turn.content,
|
|
381
|
+
source: episode.platform,
|
|
382
|
+
channelType: GROUP_CHANNEL,
|
|
383
|
+
metadata: {
|
|
384
|
+
entityName: turn.speaker,
|
|
385
|
+
type: "message",
|
|
386
|
+
trajectoryStepId: trajectoryId
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
const callbackContents = [];
|
|
391
|
+
const result = await runtime.messageService.handleMessage(
|
|
392
|
+
runtime,
|
|
393
|
+
message,
|
|
394
|
+
async (content) => {
|
|
395
|
+
callbackContents.push(content);
|
|
396
|
+
return [];
|
|
397
|
+
},
|
|
398
|
+
options.timeoutMs ? { timeoutDuration: options.timeoutMs } : void 0
|
|
399
|
+
);
|
|
400
|
+
const trajectory2 = await waitForTrajectoryDetail(logger, trajectoryId);
|
|
401
|
+
const shouldRespondCall = trajectory2?.steps?.flatMap((step) => step.llmCalls ?? []).find((call) => normalizeActionName(call.purpose) === "SHOULD_RESPOND");
|
|
402
|
+
const routingFromModel = shouldRespondCall?.response ? parseRoutingDecision(shouldRespondCall.response) : { secondaryContexts: [] };
|
|
403
|
+
const routingFallback = resolveMessageRoutingFallback(message);
|
|
404
|
+
const actualDecision = resolveActualDecision({
|
|
405
|
+
didRespond: result.didRespond,
|
|
406
|
+
callbackContents,
|
|
407
|
+
responseContent: result.responseContent ?? null,
|
|
408
|
+
shouldRespondDecision: routingFromModel.decision
|
|
409
|
+
});
|
|
410
|
+
const actualPrimaryContext = routingFromModel.primaryContext ?? routingFallback.primaryContext;
|
|
411
|
+
const actualSecondaryContexts = routingFromModel.secondaryContexts.length > 0 ? routingFromModel.secondaryContexts : routingFallback.secondaryContexts;
|
|
412
|
+
const selectedActions = [
|
|
413
|
+
.../* @__PURE__ */ new Set([
|
|
414
|
+
...collectActionNamesFromContent(result.responseContent ?? null),
|
|
415
|
+
...callbackContents.flatMap(
|
|
416
|
+
(content) => collectActionNamesFromContent(content)
|
|
417
|
+
)
|
|
418
|
+
])
|
|
419
|
+
];
|
|
420
|
+
if (!message.id) {
|
|
421
|
+
throw new Error(`Roleplay message ${turn.id} is missing an ID`);
|
|
422
|
+
}
|
|
423
|
+
const executedActions = collectExecutedActionNames(runtime, message.id);
|
|
424
|
+
const callbackTexts = callbackContents.map((content) => content.text?.trim() ?? "").filter((text) => text.length > 0);
|
|
425
|
+
const responseText = result.responseContent?.text?.trim() ?? callbackTexts[callbackTexts.length - 1] ?? "";
|
|
426
|
+
const warnings = [];
|
|
427
|
+
if (!trajectory2) {
|
|
428
|
+
warnings.push("trajectory_capture_missing");
|
|
429
|
+
}
|
|
430
|
+
if (turn.isEvaluationTarget && !routingFromModel.primaryContext && !routingFallback.primaryContext) {
|
|
431
|
+
warnings.push("context_routing_missing");
|
|
432
|
+
}
|
|
433
|
+
turnExecutions.push({
|
|
434
|
+
turnId: turn.id,
|
|
435
|
+
speaker: turn.speaker,
|
|
436
|
+
role: turn.role,
|
|
437
|
+
isEvaluationTarget: turn.isEvaluationTarget,
|
|
438
|
+
actualDecision,
|
|
439
|
+
actualPrimaryContext,
|
|
440
|
+
actualSecondaryContexts,
|
|
441
|
+
selectedActions,
|
|
442
|
+
executedActions,
|
|
443
|
+
responseText,
|
|
444
|
+
callbackTexts,
|
|
445
|
+
trajectoryId,
|
|
446
|
+
warnings
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
const evaluationTurn = turnExecutions.find((turn) => turn.isEvaluationTarget);
|
|
450
|
+
if (!evaluationTurn) {
|
|
451
|
+
throw new Error(
|
|
452
|
+
`Roleplay episode ${episode.id} has no evaluation target turn`
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
const actualActions = [
|
|
456
|
+
.../* @__PURE__ */ new Set([
|
|
457
|
+
...evaluationTurn.selectedActions,
|
|
458
|
+
...evaluationTurn.executedActions
|
|
459
|
+
])
|
|
460
|
+
];
|
|
461
|
+
const decisionMatch = evaluationTurn.actualDecision === episode.expectedDecision;
|
|
462
|
+
const primaryContextMatch = (evaluationTurn.actualPrimaryContext ?? "").toLowerCase() === episode.primaryContext.toLowerCase();
|
|
463
|
+
const secondaryContextExactMatch = secondaryContextsEqual(
|
|
464
|
+
episode.secondaryContexts,
|
|
465
|
+
evaluationTurn.actualSecondaryContexts
|
|
466
|
+
);
|
|
467
|
+
const routingMatch = primaryContextMatch && secondaryContextExactMatch;
|
|
468
|
+
const normalizedExpectedAction = episode.expectedAction ? normalizeActionName(episode.expectedAction) : "";
|
|
469
|
+
const selectedActionMatch = episode.expectedAction ? evaluationTurn.selectedActions.includes(normalizedExpectedAction) : true;
|
|
470
|
+
const executedActionMatch = episode.expectedAction ? evaluationTurn.executedActions.includes(normalizedExpectedAction) : true;
|
|
471
|
+
const actionMatch = episode.expectedAction ? actualActions.includes(normalizedExpectedAction) : true;
|
|
472
|
+
const trajectory = evaluationTurn.trajectoryId && logger ? await waitForTrajectoryDetail(logger, evaluationTurn.trajectoryId) : null;
|
|
473
|
+
return {
|
|
474
|
+
episodeId: episode.id,
|
|
475
|
+
blueprintId: episode.blueprintId,
|
|
476
|
+
agentName: episode.agentName,
|
|
477
|
+
pattern: typeof episode.metadata.pattern === "string" ? episode.metadata.pattern : void 0,
|
|
478
|
+
evaluationTurnId: episode.evaluationTurnId,
|
|
479
|
+
expectedDecision: episode.expectedDecision,
|
|
480
|
+
actualDecision: evaluationTurn.actualDecision ?? "IGNORE",
|
|
481
|
+
expectedPrimaryContext: episode.primaryContext,
|
|
482
|
+
actualPrimaryContext: evaluationTurn.actualPrimaryContext,
|
|
483
|
+
expectedSecondaryContexts: episode.secondaryContexts,
|
|
484
|
+
actualSecondaryContexts: evaluationTurn.actualSecondaryContexts,
|
|
485
|
+
expectedAction: episode.expectedAction,
|
|
486
|
+
actualActions,
|
|
487
|
+
selectedActions: evaluationTurn.selectedActions,
|
|
488
|
+
executedActions: evaluationTurn.executedActions,
|
|
489
|
+
decisionMatch,
|
|
490
|
+
primaryContextMatch,
|
|
491
|
+
secondaryContextExactMatch,
|
|
492
|
+
routingMatch,
|
|
493
|
+
actionMatch,
|
|
494
|
+
selectedActionMatch,
|
|
495
|
+
executedActionMatch,
|
|
496
|
+
trajectoryCaptured: Boolean(trajectory),
|
|
497
|
+
responseText: evaluationTurn.responseText,
|
|
498
|
+
callbackTexts: evaluationTurn.callbackTexts,
|
|
499
|
+
warnings: evaluationTurn.warnings,
|
|
500
|
+
turnExecutions,
|
|
501
|
+
trajectory
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
async function executeRoleplayEpisodes(episodes, options = {}) {
|
|
505
|
+
const runtime = await resolveRuntime(options.runtime);
|
|
506
|
+
const executions = [];
|
|
507
|
+
for (const episode of episodes) {
|
|
508
|
+
executions.push(
|
|
509
|
+
await executeRoleplayEpisode(episode, {
|
|
510
|
+
...options,
|
|
511
|
+
runtime
|
|
512
|
+
})
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
return executions;
|
|
516
|
+
}
|
|
517
|
+
function buildRoleplayExecutionReport(executions, trajectoryDatasetSummary) {
|
|
518
|
+
const totalEpisodes = executions.length;
|
|
519
|
+
const decisionMatches = executions.filter(
|
|
520
|
+
(execution) => execution.decisionMatch
|
|
521
|
+
).length;
|
|
522
|
+
const routingMatches = executions.filter(
|
|
523
|
+
(execution) => execution.routingMatch
|
|
524
|
+
).length;
|
|
525
|
+
const primaryContextMatches = executions.filter(
|
|
526
|
+
(execution) => execution.primaryContextMatch
|
|
527
|
+
).length;
|
|
528
|
+
const secondaryContextExactMatches = executions.filter(
|
|
529
|
+
(execution) => execution.secondaryContextExactMatch
|
|
530
|
+
).length;
|
|
531
|
+
const actionRelevantExecutions = executions.filter(
|
|
532
|
+
(execution) => execution.expectedAction
|
|
533
|
+
);
|
|
534
|
+
const actionMatches = actionRelevantExecutions.filter(
|
|
535
|
+
(execution) => execution.actionMatch
|
|
536
|
+
).length;
|
|
537
|
+
const selectedActionMatches = actionRelevantExecutions.filter(
|
|
538
|
+
(execution) => execution.selectedActionMatch
|
|
539
|
+
).length;
|
|
540
|
+
const executedActionMatches = actionRelevantExecutions.filter(
|
|
541
|
+
(execution) => execution.executedActionMatch
|
|
542
|
+
).length;
|
|
543
|
+
const trajectoryCaptured = executions.filter(
|
|
544
|
+
(execution) => execution.trajectoryCaptured
|
|
545
|
+
).length;
|
|
546
|
+
const decisionConfusionMatrix = createDecisionConfusionMatrix();
|
|
547
|
+
const warningCounts = {};
|
|
548
|
+
const byPrimaryContext = {};
|
|
549
|
+
const byPattern = {};
|
|
550
|
+
for (const execution of executions) {
|
|
551
|
+
decisionConfusionMatrix[execution.expectedDecision][execution.actualDecision] += 1;
|
|
552
|
+
for (const warning of execution.warnings) {
|
|
553
|
+
warningCounts[warning] = (warningCounts[warning] ?? 0) + 1;
|
|
554
|
+
}
|
|
555
|
+
const contextKey = execution.expectedPrimaryContext.toLowerCase();
|
|
556
|
+
byPrimaryContext[contextKey] ??= buildEmptyBucketReport();
|
|
557
|
+
updateBucketReport(byPrimaryContext[contextKey], execution);
|
|
558
|
+
const patternKey = execution.pattern ?? "unknown";
|
|
559
|
+
byPattern[patternKey] ??= buildEmptyBucketReport();
|
|
560
|
+
updateBucketReport(byPattern[patternKey], execution);
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
totalEpisodes,
|
|
564
|
+
decisionMatches,
|
|
565
|
+
routingMatches,
|
|
566
|
+
primaryContextMatches,
|
|
567
|
+
secondaryContextExactMatches,
|
|
568
|
+
actionMatches,
|
|
569
|
+
selectedActionMatches,
|
|
570
|
+
executedActionMatches,
|
|
571
|
+
trajectoryCaptured,
|
|
572
|
+
decisionAccuracy: decisionMatches / (totalEpisodes || 1),
|
|
573
|
+
routingAccuracy: routingMatches / (totalEpisodes || 1),
|
|
574
|
+
primaryContextAccuracy: primaryContextMatches / (totalEpisodes || 1),
|
|
575
|
+
secondaryContextExactAccuracy: secondaryContextExactMatches / (totalEpisodes || 1),
|
|
576
|
+
actionAccuracy: actionMatches / (actionRelevantExecutions.length || 1),
|
|
577
|
+
selectedActionAccuracy: selectedActionMatches / (actionRelevantExecutions.length || 1),
|
|
578
|
+
executedActionAccuracy: executedActionMatches / (actionRelevantExecutions.length || 1),
|
|
579
|
+
trajectoryCaptureRate: trajectoryCaptured / (totalEpisodes || 1),
|
|
580
|
+
decisionConfusionMatrix,
|
|
581
|
+
warningCounts,
|
|
582
|
+
byPrimaryContext: Object.fromEntries(
|
|
583
|
+
Object.entries(byPrimaryContext).map(([context, bucket]) => [
|
|
584
|
+
context,
|
|
585
|
+
finalizeBucketReport(bucket)
|
|
586
|
+
])
|
|
587
|
+
),
|
|
588
|
+
byPattern: Object.fromEntries(
|
|
589
|
+
Object.entries(byPattern).map(([pattern, bucket]) => [
|
|
590
|
+
pattern,
|
|
591
|
+
finalizeBucketReport(bucket)
|
|
592
|
+
])
|
|
593
|
+
),
|
|
594
|
+
trajectoryDatasetSummary,
|
|
595
|
+
mismatches: executions.filter(
|
|
596
|
+
(execution) => !execution.decisionMatch || !execution.routingMatch || !execution.actionMatch || !execution.selectedActionMatch || !execution.executedActionMatch
|
|
597
|
+
).map((execution) => ({
|
|
598
|
+
episodeId: execution.episodeId,
|
|
599
|
+
pattern: execution.pattern,
|
|
600
|
+
expectedDecision: execution.expectedDecision,
|
|
601
|
+
actualDecision: execution.actualDecision,
|
|
602
|
+
expectedPrimaryContext: execution.expectedPrimaryContext,
|
|
603
|
+
actualPrimaryContext: execution.actualPrimaryContext,
|
|
604
|
+
expectedAction: execution.expectedAction,
|
|
605
|
+
actualActions: execution.actualActions,
|
|
606
|
+
selectedActions: execution.selectedActions,
|
|
607
|
+
executedActions: execution.executedActions,
|
|
608
|
+
warnings: execution.warnings
|
|
609
|
+
}))
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
async function exportRoleplayExecutionResults(executions, outputDir) {
|
|
613
|
+
await mkdir(outputDir, { recursive: true });
|
|
614
|
+
const executionsPath = join(outputDir, "roleplay_execution_results.json");
|
|
615
|
+
const reportPath = join(outputDir, "roleplay_execution_report.json");
|
|
616
|
+
const trajectories = executions.map((execution) => execution.trajectory).filter((trajectory) => Boolean(trajectory));
|
|
617
|
+
const trajectoryDataset = trajectories.length > 0 ? await exportTrajectoryTaskDatasets(
|
|
618
|
+
trajectories,
|
|
619
|
+
join(outputDir, "trajectory-datasets")
|
|
620
|
+
) : void 0;
|
|
621
|
+
const report = buildRoleplayExecutionReport(
|
|
622
|
+
executions,
|
|
623
|
+
trajectoryDataset?.summary ?? null
|
|
624
|
+
);
|
|
625
|
+
await writeFile(executionsPath, JSON.stringify(executions, null, 2));
|
|
626
|
+
await writeFile(reportPath, JSON.stringify(report, null, 2));
|
|
627
|
+
return {
|
|
628
|
+
executionsPath,
|
|
629
|
+
reportPath,
|
|
630
|
+
trajectoryDataset
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
async function loadRoleplayEpisodesFromPath(inputPath) {
|
|
634
|
+
const raw = await readFile(inputPath, "utf-8");
|
|
635
|
+
if (inputPath.endsWith(".jsonl")) {
|
|
636
|
+
return raw.split("\n").map((line) => line.trim()).filter(Boolean).map((line) => JSON.parse(line)).map((line) => ({
|
|
637
|
+
id: line.episodeId,
|
|
638
|
+
blueprintId: line.blueprintId,
|
|
639
|
+
agentName: line.agentName,
|
|
640
|
+
platform: "group-chat",
|
|
641
|
+
roomType: "group",
|
|
642
|
+
primaryContext: line.primaryContext,
|
|
643
|
+
secondaryContexts: line.secondaryContexts,
|
|
644
|
+
expectedDecision: line.expectedDecision,
|
|
645
|
+
expectedAction: line.expectedAction,
|
|
646
|
+
evaluationTurnId: line.evaluationTurnId,
|
|
647
|
+
turns: line.conversation.map((turn) => ({
|
|
648
|
+
id: turn.id,
|
|
649
|
+
role: turn.role,
|
|
650
|
+
speaker: turn.speaker,
|
|
651
|
+
content: turn.content,
|
|
652
|
+
isEvaluationTarget: turn.id === line.evaluationTurnId
|
|
653
|
+
})),
|
|
654
|
+
metadata: {
|
|
655
|
+
pattern: "manifest-import",
|
|
656
|
+
generatedBy: "manifest",
|
|
657
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
658
|
+
sourceSampleId: line.episodeId
|
|
659
|
+
}
|
|
660
|
+
}));
|
|
661
|
+
}
|
|
662
|
+
const parsed = JSON.parse(raw);
|
|
663
|
+
if (!Array.isArray(parsed)) {
|
|
664
|
+
throw new Error(`Expected an array of roleplay episodes in ${inputPath}`);
|
|
665
|
+
}
|
|
666
|
+
return parsed;
|
|
667
|
+
}
|
|
668
|
+
export {
|
|
669
|
+
buildRoleplayExecutionReport,
|
|
670
|
+
executeRoleplayEpisode,
|
|
671
|
+
executeRoleplayEpisodes,
|
|
672
|
+
exportRoleplayExecutionResults,
|
|
673
|
+
loadRoleplayEpisodesFromPath
|
|
674
|
+
};
|
|
675
|
+
//# sourceMappingURL=roleplay-executor.js.map
|