textopt 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +509 -0
  3. package/dist/bootstrap-search/index.cjs +308 -0
  4. package/dist/bootstrap-search/index.d.cts +162 -0
  5. package/dist/bootstrap-search/index.d.mts +162 -0
  6. package/dist/bootstrap-search/index.mjs +307 -0
  7. package/dist/cache-CuSo0NJ8.d.cts +24 -0
  8. package/dist/cache-CuSo0NJ8.d.mts +24 -0
  9. package/dist/concurrency-C-cFzWW2.cjs +44 -0
  10. package/dist/concurrency-D58PWeSk.mjs +39 -0
  11. package/dist/demos-B0pVQjYC.d.mts +88 -0
  12. package/dist/demos-B9BJiNKz.cjs +143 -0
  13. package/dist/demos-BTuzFNsp.d.cts +88 -0
  14. package/dist/demos-Degx6UmP.mjs +126 -0
  15. package/dist/evaluation-BV0nSZVx.mjs +521 -0
  16. package/dist/evaluation-OZOp6TB7.cjs +598 -0
  17. package/dist/file-cache.cjs +70 -0
  18. package/dist/file-cache.d.cts +21 -0
  19. package/dist/file-cache.d.mts +21 -0
  20. package/dist/file-cache.mjs +69 -0
  21. package/dist/gepa/index.cjs +1671 -0
  22. package/dist/gepa/index.d.cts +385 -0
  23. package/dist/gepa/index.d.mts +385 -0
  24. package/dist/gepa/index.mjs +1652 -0
  25. package/dist/index.cjs +266 -0
  26. package/dist/index.d.cts +221 -0
  27. package/dist/index.d.mts +221 -0
  28. package/dist/index.mjs +245 -0
  29. package/dist/math-COOofUyv.cjs +101 -0
  30. package/dist/math-DhrDmpFS.mjs +78 -0
  31. package/dist/mipro/index.cjs +739 -0
  32. package/dist/mipro/index.d.cts +372 -0
  33. package/dist/mipro/index.d.mts +372 -0
  34. package/dist/mipro/index.mjs +736 -0
  35. package/dist/opro/index.cjs +487 -0
  36. package/dist/opro/index.d.cts +230 -0
  37. package/dist/opro/index.d.mts +230 -0
  38. package/dist/opro/index.mjs +485 -0
  39. package/dist/optimizer-B7SpRwl7.d.cts +288 -0
  40. package/dist/optimizer-DqCoth_w.d.mts +288 -0
  41. package/dist/random-search/index.cjs +321 -0
  42. package/dist/random-search/index.d.cts +156 -0
  43. package/dist/random-search/index.d.mts +156 -0
  44. package/dist/random-search/index.mjs +319 -0
  45. package/dist/reflection-CQToe-5B.d.cts +283 -0
  46. package/dist/reflection-Cr_upzU0.d.mts +283 -0
  47. package/dist/reflection-DRfbk6hu.cjs +249 -0
  48. package/dist/reflection-mwMhrjs_.mjs +214 -0
  49. package/dist/rng-BR5MOedA.d.cts +22 -0
  50. package/dist/rng-BR5MOedA.d.mts +22 -0
  51. package/dist/rng-DbA_rPIo.cjs +67 -0
  52. package/dist/rng-Dtc5eZ_W.mjs +62 -0
  53. package/dist/sampling-CfHt7Gue.mjs +59 -0
  54. package/dist/sampling-DFo_7RNJ.d.mts +23 -0
  55. package/dist/sampling-Dars7ctR.cjs +64 -0
  56. package/dist/sampling-axOwfZf5.d.cts +23 -0
  57. package/dist/simba/index.cjs +709 -0
  58. package/dist/simba/index.d.cts +289 -0
  59. package/dist/simba/index.d.mts +289 -0
  60. package/dist/simba/index.mjs +700 -0
  61. package/dist/testing.cjs +155 -0
  62. package/dist/testing.d.cts +53 -0
  63. package/dist/testing.d.mts +53 -0
  64. package/dist/testing.mjs +148 -0
  65. package/dist/text--v4Ffbus.mjs +21 -0
  66. package/dist/text-CK_HB3su.cjs +26 -0
  67. package/dist/types-CWv4IQFF.d.cts +129 -0
  68. package/dist/types-CWv4IQFF.d.mts +129 -0
  69. package/package.json +135 -0
@@ -0,0 +1,129 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * A candidate is a map of named text components to their current text. This is
4
+ * the unit of optimization — prompts, instructions, code, tool descriptions,
5
+ * anything expressible as a named string.
6
+ *
7
+ * `K` is the union of component names, inferred from the seed candidate, so a
8
+ * misspelled component is a compile error rather than a silent no-op.
9
+ */
10
+ type Candidate<K extends string = string> = Record<K, string>;
11
+ /**
12
+ * What one rollout consumed. Every field is optional because providers report
13
+ * different subsets, and a partial reading is still worth more than none.
14
+ */
15
+ interface RolloutUsage {
16
+ inputTokens?: number;
17
+ outputTokens?: number;
18
+ /** Defaults to the sum of the two token counts when they are reported. */
19
+ totalTokens?: number;
20
+ costUsd?: number;
21
+ }
22
+ /** Usage summed over a run, alongside the rollouts that produced it. */
23
+ interface UsageTotals {
24
+ inputTokens: number;
25
+ outputTokens: number;
26
+ totalTokens: number;
27
+ costUsd: number;
28
+ /** Fresh rollouts counted here. Cached instances buy nothing. */
29
+ rollouts: number;
30
+ }
31
+ /**
32
+ * Result of running a candidate over a batch of data instances.
33
+ *
34
+ * `scores` is the load-bearing field: one number per instance, higher is
35
+ * better. `feedback` is a per-instance textual diagnosis of what went wrong,
36
+ * which a reflective optimizer reads to write a better candidate.
37
+ */
38
+ interface EvaluationBatch<Trajectory = unknown, Output = unknown> {
39
+ outputs: Output[];
40
+ scores: number[];
41
+ /**
42
+ * What each rollout consumed. Rollout counts are the budget, but they are a
43
+ * poor proxy for spend: reflective search grows the text it optimizes, so
44
+ * the same rollout costs more late in a run than early in it.
45
+ */
46
+ usage?: RolloutUsage[];
47
+ feedback?: string[];
48
+ trajectories?: Trajectory[];
49
+ objectiveScores?: Record<string, number>[];
50
+ /**
51
+ * Per-instance: true when the score reflects an infrastructure failure
52
+ * rather than the candidate's behaviour. Transient scores are never written
53
+ * to the evaluation cache.
54
+ */
55
+ transient?: boolean[];
56
+ }
57
+ /**
58
+ * What a per-instance scorer returns. Shared by every adapter so scorers are
59
+ * portable between them — a Braintrust scorer works in a LangChain run.
60
+ */
61
+ interface ScoreResult {
62
+ score: number;
63
+ feedback?: string;
64
+ objectiveScores?: Record<string, number>;
65
+ /** What this rollout consumed, when the caller can see it. */
66
+ usage?: RolloutUsage;
67
+ /**
68
+ * Marks a score produced by an infrastructure failure — a rate limit, a
69
+ * network blip, a provider 5xx — rather than by the candidate. Without this
70
+ * the engine cannot tell such a zero from a genuine one, and would cache it
71
+ * permanently against the candidate.
72
+ */
73
+ transient?: boolean;
74
+ }
75
+ interface EvaluateArgs<Datum, K extends string = string> {
76
+ batch: readonly Datum[];
77
+ candidate: Candidate<K>;
78
+ captureTraces: boolean;
79
+ /**
80
+ * Where this batch sits in the run. Forward it to whatever tracing the
81
+ * system under optimization already has — without it a run is thousands of
82
+ * indistinguishable rollouts, and no trace can be tied back to the iteration
83
+ * whose score moved.
84
+ */
85
+ run: EvaluationContext;
86
+ signal?: AbortSignal;
87
+ }
88
+ /**
89
+ * Identifies one evaluation within a run. `candidateId` is null while the
90
+ * candidate is still a proposal being screened on a minibatch: it has no
91
+ * record, and inventing an id for it would collide with the one it gets if it
92
+ * is accepted.
93
+ */
94
+ interface EvaluationContext {
95
+ iteration: number;
96
+ phase: EvaluationPhase;
97
+ split: EvaluationSplit;
98
+ candidateId: number | null;
99
+ }
100
+ type EvaluationPhase = "seed" | "minibatch" | "validation" | "test";
101
+ /**
102
+ * Which dataset an instance id was drawn from. Each split numbers its ids
103
+ * independently, so the same id can name three different instances; the cache
104
+ * key has to keep them apart.
105
+ */
106
+ type EvaluationSplit = "train" | "val" | "test";
107
+ /**
108
+ * The single integration seam between an optimizer and a system under
109
+ * optimization. Everything framework-specific — LangChain, the AI SDK,
110
+ * Braintrust — lives in an implementation of this interface.
111
+ */
112
+ interface Adapter<Datum, Trajectory = unknown, Output = unknown, K extends string = string> {
113
+ evaluate(args: EvaluateArgs<Datum, K>): Promise<EvaluationBatch<Trajectory, Output>> | EvaluationBatch<Trajectory, Output>;
114
+ }
115
+ /** Provider-agnostic text model: text in, text out. */
116
+ type TextModel = (args: {
117
+ prompt: string;
118
+ signal?: AbortSignal;
119
+ }) => Promise<string>;
120
+ /**
121
+ * The component names of a candidate, as the union they were inferred from.
122
+ *
123
+ * `Object.keys` widens a closed key union back to `string`. This is the one
124
+ * place that narrowing happens, so every other caller stays assertion-free.
125
+ * Accepts a partial so it also names the components of a component patch.
126
+ */
127
+ declare function componentNames<K extends string>(candidate: Partial<Candidate<K>>): K[];
128
+ //#endregion
129
+ export { EvaluationContext as a, RolloutUsage as c, UsageTotals as d, componentNames as f, EvaluationBatch as i, ScoreResult as l, Candidate as n, EvaluationPhase as o, EvaluateArgs as r, EvaluationSplit as s, Adapter as t, TextModel as u };
package/package.json ADDED
@@ -0,0 +1,135 @@
1
+ {
2
+ "name": "textopt",
3
+ "version": "0.0.0",
4
+ "description": "Prompt optimization for TypeScript, with GEPA, OPRO, MIPRO, and random search behind a shared interface",
5
+ "keywords": [
6
+ "prompt-optimization",
7
+ "gepa",
8
+ "mipro",
9
+ "opro",
10
+ "llm",
11
+ "prompt-engineering",
12
+ "dspy",
13
+ "evaluation"
14
+ ],
15
+ "license": "MIT",
16
+ "homepage": "https://github.com/ctdio/textopt#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/ctdio/textopt.git",
20
+ "directory": "packages/core"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/ctdio/textopt/issues"
24
+ },
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "engines": {
28
+ "node": ">=20"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "import": {
36
+ "types": "./dist/index.d.mts",
37
+ "default": "./dist/index.mjs"
38
+ },
39
+ "require": {
40
+ "types": "./dist/index.d.cts",
41
+ "default": "./dist/index.cjs"
42
+ }
43
+ },
44
+ "./file-cache": {
45
+ "import": {
46
+ "types": "./dist/file-cache.d.mts",
47
+ "default": "./dist/file-cache.mjs"
48
+ },
49
+ "require": {
50
+ "types": "./dist/file-cache.d.cts",
51
+ "default": "./dist/file-cache.cjs"
52
+ }
53
+ },
54
+ "./gepa": {
55
+ "import": {
56
+ "types": "./dist/gepa/index.d.mts",
57
+ "default": "./dist/gepa/index.mjs"
58
+ },
59
+ "require": {
60
+ "types": "./dist/gepa/index.d.cts",
61
+ "default": "./dist/gepa/index.cjs"
62
+ }
63
+ },
64
+ "./simba": {
65
+ "import": {
66
+ "types": "./dist/simba/index.d.mts",
67
+ "default": "./dist/simba/index.mjs"
68
+ },
69
+ "require": {
70
+ "types": "./dist/simba/index.d.cts",
71
+ "default": "./dist/simba/index.cjs"
72
+ }
73
+ },
74
+ "./testing": {
75
+ "import": {
76
+ "types": "./dist/testing.d.mts",
77
+ "default": "./dist/testing.mjs"
78
+ },
79
+ "require": {
80
+ "types": "./dist/testing.d.cts",
81
+ "default": "./dist/testing.cjs"
82
+ }
83
+ },
84
+ "./random-search": {
85
+ "import": {
86
+ "types": "./dist/random-search/index.d.mts",
87
+ "default": "./dist/random-search/index.mjs"
88
+ },
89
+ "require": {
90
+ "types": "./dist/random-search/index.d.cts",
91
+ "default": "./dist/random-search/index.cjs"
92
+ }
93
+ },
94
+ "./opro": {
95
+ "import": {
96
+ "types": "./dist/opro/index.d.mts",
97
+ "default": "./dist/opro/index.mjs"
98
+ },
99
+ "require": {
100
+ "types": "./dist/opro/index.d.cts",
101
+ "default": "./dist/opro/index.cjs"
102
+ }
103
+ },
104
+ "./bootstrap-search": {
105
+ "import": {
106
+ "types": "./dist/bootstrap-search/index.d.mts",
107
+ "default": "./dist/bootstrap-search/index.mjs"
108
+ },
109
+ "require": {
110
+ "types": "./dist/bootstrap-search/index.d.cts",
111
+ "default": "./dist/bootstrap-search/index.cjs"
112
+ }
113
+ },
114
+ "./mipro": {
115
+ "import": {
116
+ "types": "./dist/mipro/index.d.mts",
117
+ "default": "./dist/mipro/index.mjs"
118
+ },
119
+ "require": {
120
+ "types": "./dist/mipro/index.d.cts",
121
+ "default": "./dist/mipro/index.cjs"
122
+ }
123
+ }
124
+ },
125
+ "main": "./dist/index.cjs",
126
+ "module": "./dist/index.mjs",
127
+ "types": "./dist/index.d.cts",
128
+ "files": [
129
+ "dist"
130
+ ],
131
+ "scripts": {
132
+ "build": "tsdown",
133
+ "typecheck": "tsc --noEmit"
134
+ }
135
+ }