@gobing-ai/ts-ai-runner 0.8.5 → 0.8.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.
@@ -9,6 +9,19 @@ export interface DecisionMaker {
9
9
  questions: Q;
10
10
  model?: string;
11
11
  }): Promise<AnswersFor<Q>>;
12
+ /**
13
+ * `ask` plus the model the backend actually served (P12 R1/R2), or no `servedModel` when the
14
+ * driver cannot report one. Optional: a maker object registered directly need not implement it,
15
+ * and `createDecisionMaker` always does. Validation is identical on both paths.
16
+ */
17
+ askWithMeta?<const Q extends Record<string, Question>>(req: {
18
+ state: DecisionState;
19
+ questions: Q;
20
+ model?: string;
21
+ }): Promise<{
22
+ answers: AnswersFor<Q>;
23
+ servedModel?: string;
24
+ }>;
12
25
  /** Pick one label. Sugar over `ask` with exactly one choice question. */
13
26
  choice<const L extends string>(state: DecisionState, prompt: Desc, labels: Record<L, Desc>): Promise<ChoiceAnswer<L>>;
14
27
  /** Score against a rubric. Sugar over `ask` with exactly one score question. */
@@ -75,9 +88,17 @@ export declare function resolveLayaDriver(options: DecisionMakerOptions, importM
75
88
  export declare function resolveTypesafeDriver(options: DecisionMakerOptions, importModule?: (specifier: string) => Promise<unknown>): Promise<DecisionDriver>;
76
89
  /** @internal Exported for task 0086 R9 branch tests; see {@link resolveLayaDriver}. */
77
90
  export declare function resolveFmDriver(options: DecisionMakerOptions, importModule?: (specifier: string) => Promise<unknown>): Promise<DecisionDriver>;
91
+ /**
92
+ * A maker built by {@link createDecisionMaker}: the optional meta seam is always implemented, so a
93
+ * caller that wants the served model calls it without a presence check. A maker object registered
94
+ * directly (a test double, a foreign implementation) keeps the optional shape.
95
+ */
96
+ export type DecisionMakerWithMeta = DecisionMaker & {
97
+ askWithMeta: NonNullable<DecisionMaker['askWithMeta']>;
98
+ };
78
99
  /**
79
100
  * Build a DecisionMaker. `options.driver` wins when supplied; otherwise `options.backend`
80
101
  * resolves the driver (default `'typesafe'`). The driver is constructed lazily on first use.
81
102
  */
82
- export declare function createDecisionMaker(options?: DecisionMakerOptions): DecisionMaker;
103
+ export declare function createDecisionMaker(options?: DecisionMakerOptions): DecisionMakerWithMeta;
83
104
  //# sourceMappingURL=decision-maker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decision-maker.d.ts","sourceRoot":"","sources":["../../src/decision/decision-maker.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,UAAU,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,WAAW,EACd,MAAM,SAAS,CAAC;AAIjB,yFAAyF;AACzF,MAAM,WAAW,aAAa;IAC1B,iFAAiF;IACjF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sFAAsF;IACtF,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE;QAC/C,KAAK,EAAE,aAAa,CAAC;QACrB,SAAS,EAAE,CAAC,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,yEAAyE;IACzE,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EACzB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,IAAI,EACZ,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,GACxB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,gFAAgF;IAChF,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1G,wEAAwE;IACxE,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,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,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAUnE;AAID;;;;GAIG;AACH,wBAAsB,iBAAiB,CACnC,OAAO,EAAE,oBAAoB,EAC7B,YAAY,GAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAoC,GACzF,OAAO,CAAC,cAAc,CAAC,CAuBzB;AAID;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACvC,OAAO,EAAE,oBAAoB,EAC7B,YAAY,GAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAoC,GACzF,OAAO,CAAC,cAAc,CAAC,CA4BzB;AAID,uFAAuF;AACvF,wBAAsB,eAAe,CACjC,OAAO,EAAE,oBAAoB,EAC7B,YAAY,GAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAoC,GACzF,OAAO,CAAC,cAAc,CAAC,CAkBzB;AAED;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG;IAChD,WAAW,EAAE,WAAW,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,qBAAqB,CAyE7F"}
@@ -124,6 +124,18 @@ export function createDecisionMaker(options = {}) {
124
124
  // Runtime validation above establishes each question/answer correspondence.
125
125
  return answers;
126
126
  };
127
+ const askWithMeta = async (req) => {
128
+ const driver = await getDriver();
129
+ validateQuestions(req.questions);
130
+ // R2: prefer the driver's meta seam and fall back to plain `ask` — the answer validation
131
+ // below is shared, so a driver that cannot report a model behaves exactly as it does today.
132
+ const meta = driver.askWithMeta ? await driver.askWithMeta(req) : { answers: await driver.ask(req) };
133
+ validateAnswers(req.questions, meta.answers);
134
+ // Runtime validation above establishes each question/answer correspondence.
135
+ const answers = meta.answers;
136
+ // Absent, never an explicit undefined: consumers distinguish "no model reported" by absense.
137
+ return meta.servedModel === undefined ? { answers } : { answers, servedModel: meta.servedModel };
138
+ };
127
139
  return {
128
140
  driver: options.driver?.name ?? options.backend ?? 'typesafe',
129
141
  // Only an injected or already-resolved driver is a candidate: running the lazy factory
@@ -133,6 +145,7 @@ export function createDecisionMaker(options = {}) {
133
145
  await (options.driver ?? resolvedDriver)?.dispose?.();
134
146
  },
135
147
  ask,
148
+ askWithMeta,
136
149
  // R4/R5: each sugar method is one `ask` with exactly one `q.*` question,
137
150
  // unwrapping the single answer — no second driver call, no duplicated
138
151
  // request assembly.
@@ -89,6 +89,15 @@ export declare const q: {
89
89
  no?: Desc;
90
90
  }) => NoulQuestion;
91
91
  };
92
+ /**
93
+ * Answers plus the model that actually served them (P12 R3): `servedModel` is what the backend
94
+ * reports it used, which can differ from the requested model under routing. Absent whenever the
95
+ * driver reports none — a fallback, a local process, or an agent CLI with no model identity.
96
+ */
97
+ export interface DecisionAnswersMeta {
98
+ answers: Record<string, Answer>;
99
+ servedModel?: string;
100
+ }
92
101
  /**
93
102
  * The one-method internal seam every backend driver implements. The loose
94
103
  * `Record<string, Answer>` return is narrowed to `AnswersFor<Q>` by a single
@@ -101,6 +110,15 @@ export interface DecisionDriver {
101
110
  questions: Record<string, Question>;
102
111
  model?: string;
103
112
  }): Promise<Record<string, Answer>>;
113
+ /**
114
+ * `ask` plus the served model (P12 R1). Optional and additive: a driver that cannot report a
115
+ * model omits it, and every caller keeps working through `ask` alone.
116
+ */
117
+ askWithMeta?(req: {
118
+ state: DecisionState;
119
+ questions: Record<string, Question>;
120
+ model?: string;
121
+ }): Promise<DecisionAnswersMeta>;
104
122
  /**
105
123
  * Release whatever the driver owns outside the JS heap — a warm worker process, a socket, a
106
124
  * pool. Optional: a driver that owns no such resource omits it. Must be safe to call more than
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/decision/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,mCAAmC;AACnC,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAErF,mFAAmF;AACnF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,EAAE,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,CAAC;AAE3E,0FAA0F;AAC1F,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,IAAI,EAAE,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,CAAC;AAElE,+EAA+E;AAC/E,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;CAAE,CAAC;AAE1G,6EAA6E;AAC7E,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAEvG,qEAAqE;AACrE,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAAC,EAAE,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAElF,iDAAiD;AACjD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CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,GAAG,EAAE;QACL,KAAK,EAAE,aAAa,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACpC,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpC;;;OAGG;IACH,WAAW,CAAC,CAAC,GAAG,EAAE;QACd,KAAK,EAAE,aAAa,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACpC,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACjC;;;;OAIG;IACH,OAAO,CAAC,IAAI,IAAI,CAAC;CACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobing-ai/ts-ai-runner",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "@gobing-ai/ts-ai-runner — Coding-agent shims, detection, doctor checks, and prompt execution.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -51,12 +51,12 @@
51
51
  "release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-ai-runner-v<version> && git push --tags' && exit 1"
52
52
  },
53
53
  "dependencies": {
54
- "@gobing-ai/ts-infra": "^0.8.5",
55
- "@gobing-ai/ts-runtime": "^0.8.5"
54
+ "@gobing-ai/ts-infra": "^0.8.7",
55
+ "@gobing-ai/ts-runtime": "^0.8.7"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/bun": "1.4.3",
59
- "@gobing-ai/ts-db": "^0.8.5"
59
+ "@gobing-ai/ts-db": "^0.8.7"
60
60
  },
61
61
  "publishConfig": {
62
62
  "access": "public"
@@ -29,6 +29,16 @@ export interface DecisionMaker {
29
29
  questions: Q;
30
30
  model?: string;
31
31
  }): Promise<AnswersFor<Q>>;
32
+ /**
33
+ * `ask` plus the model the backend actually served (P12 R1/R2), or no `servedModel` when the
34
+ * driver cannot report one. Optional: a maker object registered directly need not implement it,
35
+ * and `createDecisionMaker` always does. Validation is identical on both paths.
36
+ */
37
+ askWithMeta?<const Q extends Record<string, Question>>(req: {
38
+ state: DecisionState;
39
+ questions: Q;
40
+ model?: string;
41
+ }): Promise<{ answers: AnswersFor<Q>; servedModel?: string }>;
32
42
  /** Pick one label. Sugar over `ask` with exactly one choice question. */
33
43
  choice<const L extends string>(
34
44
  state: DecisionState,
@@ -197,11 +207,20 @@ export async function resolveFmDriver(
197
207
  return mod.createFmDriver(options);
198
208
  }
199
209
 
210
+ /**
211
+ * A maker built by {@link createDecisionMaker}: the optional meta seam is always implemented, so a
212
+ * caller that wants the served model calls it without a presence check. A maker object registered
213
+ * directly (a test double, a foreign implementation) keeps the optional shape.
214
+ */
215
+ export type DecisionMakerWithMeta = DecisionMaker & {
216
+ askWithMeta: NonNullable<DecisionMaker['askWithMeta']>;
217
+ };
218
+
200
219
  /**
201
220
  * Build a DecisionMaker. `options.driver` wins when supplied; otherwise `options.backend`
202
221
  * resolves the driver (default `'typesafe'`). The driver is constructed lazily on first use.
203
222
  */
204
- export function createDecisionMaker(options: DecisionMakerOptions = {}): DecisionMaker {
223
+ export function createDecisionMaker(options: DecisionMakerOptions = {}): DecisionMakerWithMeta {
205
224
  let resolvedDriver: DecisionDriver | undefined;
206
225
  const getDriver = async (): Promise<DecisionDriver> => {
207
226
  if (options.driver) return options.driver;
@@ -237,6 +256,23 @@ export function createDecisionMaker(options: DecisionMakerOptions = {}): Decisio
237
256
  return answers as AnswersFor<Q>;
238
257
  };
239
258
 
259
+ const askWithMeta = async <const Q extends Record<string, Question>>(req: {
260
+ state: DecisionState;
261
+ questions: Q;
262
+ model?: string;
263
+ }): Promise<{ answers: AnswersFor<Q>; servedModel?: string }> => {
264
+ const driver = await getDriver();
265
+ validateQuestions(req.questions);
266
+ // R2: prefer the driver's meta seam and fall back to plain `ask` — the answer validation
267
+ // below is shared, so a driver that cannot report a model behaves exactly as it does today.
268
+ const meta = driver.askWithMeta ? await driver.askWithMeta(req) : { answers: await driver.ask(req) };
269
+ validateAnswers(req.questions, meta.answers);
270
+ // Runtime validation above establishes each question/answer correspondence.
271
+ const answers = meta.answers as AnswersFor<Q>;
272
+ // Absent, never an explicit undefined: consumers distinguish "no model reported" by absense.
273
+ return meta.servedModel === undefined ? { answers } : { answers, servedModel: meta.servedModel };
274
+ };
275
+
240
276
  return {
241
277
  driver: options.driver?.name ?? options.backend ?? 'typesafe',
242
278
  // Only an injected or already-resolved driver is a candidate: running the lazy factory
@@ -246,6 +282,7 @@ export function createDecisionMaker(options: DecisionMakerOptions = {}): Decisio
246
282
  await (options.driver ?? resolvedDriver)?.dispose?.();
247
283
  },
248
284
  ask,
285
+ askWithMeta,
249
286
  // R4/R5: each sugar method is one `ask` with exactly one `q.*` question,
250
287
  // unwrapping the single answer — no second driver call, no duplicated
251
288
  // request assembly.
@@ -96,6 +96,16 @@ export const q = {
96
96
  }),
97
97
  };
98
98
 
99
+ /**
100
+ * Answers plus the model that actually served them (P12 R3): `servedModel` is what the backend
101
+ * reports it used, which can differ from the requested model under routing. Absent whenever the
102
+ * driver reports none — a fallback, a local process, or an agent CLI with no model identity.
103
+ */
104
+ export interface DecisionAnswersMeta {
105
+ answers: Record<string, Answer>;
106
+ servedModel?: string;
107
+ }
108
+
99
109
  /**
100
110
  * The one-method internal seam every backend driver implements. The loose
101
111
  * `Record<string, Answer>` return is narrowed to `AnswersFor<Q>` by a single
@@ -108,6 +118,15 @@ export interface DecisionDriver {
108
118
  questions: Record<string, Question>;
109
119
  model?: string;
110
120
  }): Promise<Record<string, Answer>>;
121
+ /**
122
+ * `ask` plus the served model (P12 R1). Optional and additive: a driver that cannot report a
123
+ * model omits it, and every caller keeps working through `ask` alone.
124
+ */
125
+ askWithMeta?(req: {
126
+ state: DecisionState;
127
+ questions: Record<string, Question>;
128
+ model?: string;
129
+ }): Promise<DecisionAnswersMeta>;
111
130
  /**
112
131
  * Release whatever the driver owns outside the JS heap — a warm worker process, a socket, a
113
132
  * pool. Optional: a driver that owns no such resource omits it. Must be safe to call more than