@valerypopoff/rivet2-core 2.22.1 → 2.25.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 (80) hide show
  1. package/dist/cjs/bundle.cjs +1438 -824
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/interpolationRuntime.cjs +23 -0
  4. package/dist/cjs/interpolationRuntime.cjs.map +3 -3
  5. package/dist/cjs/serialization.cjs +1 -0
  6. package/dist/cjs/serialization.cjs.map +2 -2
  7. package/dist/cjs/webAppRuntime.cjs +4 -1
  8. package/dist/cjs/webAppRuntime.cjs.map +2 -2
  9. package/dist/esm/exports.js +3 -1
  10. package/dist/esm/index.js +3 -0
  11. package/dist/esm/integrations/CodeRunner.js +6 -3
  12. package/dist/esm/integrations/CodeRunnerNamespace.js +10 -0
  13. package/dist/esm/model/AgentResponseTracePresentation.js +5 -1
  14. package/dist/esm/model/ChildInvocationOwnership.js +51 -0
  15. package/dist/esm/model/DatasetOwnership.js +9 -0
  16. package/dist/esm/model/GraphExecutionState.js +3 -0
  17. package/dist/esm/model/GraphProcessor.js +94 -55
  18. package/dist/esm/model/NodeRegistration.js +2 -6
  19. package/dist/esm/model/RunCostLedger.js +58 -0
  20. package/dist/esm/model/chat-v2/chatV2CallObserver.js +2 -2
  21. package/dist/esm/model/chat-v2/chatV2Outputs.js +1 -1
  22. package/dist/esm/model/chat-v2/chatV2Pipeline.js +5 -0
  23. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +3 -0
  24. package/dist/esm/model/chat-v2/llmModelCandidate.js +3 -0
  25. package/dist/esm/model/chat-v2/llmProfile.js +2 -0
  26. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +1 -0
  27. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +2 -1
  28. package/dist/esm/model/chat-v2/modelRegistry.js +12 -3
  29. package/dist/esm/model/classifier/baseten.js +78 -0
  30. package/dist/esm/model/classifier/credentials.js +17 -9
  31. package/dist/esm/model/classifier/images.js +4 -4
  32. package/dist/esm/model/classifier/jev.js +45 -0
  33. package/dist/esm/model/classifier/json.js +1 -1
  34. package/dist/esm/model/classifier/limits.js +13 -13
  35. package/dist/esm/model/classifier/openai.js +20 -2
  36. package/dist/esm/model/classifier/preparation.js +5 -5
  37. package/dist/esm/model/classifier/profile.js +24 -15
  38. package/dist/esm/model/classifier/profileExecution.js +28 -24
  39. package/dist/esm/model/classifier/providers.js +194 -87
  40. package/dist/esm/model/classifier/questionHelpers.js +21 -2
  41. package/dist/esm/model/classifier/questions.js +37 -7
  42. package/dist/esm/model/classifier/response.js +8 -2
  43. package/dist/esm/model/classifier/state.js +2 -2
  44. package/dist/esm/model/classifier/subq.js +51 -0
  45. package/dist/esm/model/nodes/ClassifierEvaluateNode.js +48 -66
  46. package/dist/esm/model/nodes/ClassifierProfileNode.js +11 -9
  47. package/dist/esm/model/nodes/ClassifierQuestionNode.js +53 -34
  48. package/dist/esm/model/tokenPricing.js +52 -0
  49. package/dist/esm/model/tokenPricingEditor.js +9 -0
  50. package/dist/types/exports.d.ts +3 -0
  51. package/dist/types/index.d.ts +1 -1
  52. package/dist/types/integrations/CodeRunner.d.ts +4 -1
  53. package/dist/types/integrations/CodeRunnerNamespace.d.ts +5 -0
  54. package/dist/types/model/AgentResponseTracePresentation.d.ts +2 -0
  55. package/dist/types/model/ChildInvocationOwnership.d.ts +36 -0
  56. package/dist/types/model/DatasetOwnership.d.ts +5 -0
  57. package/dist/types/model/GraphExecutionState.d.ts +2 -0
  58. package/dist/types/model/GraphProcessor.d.ts +3 -0
  59. package/dist/types/model/RunCostLedger.d.ts +19 -0
  60. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +1 -1
  61. package/dist/types/model/chat-v2/chatV2Types.d.ts +2 -0
  62. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +3 -1
  63. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +7 -5
  64. package/dist/types/model/chat-v2/modelRegistry.d.ts +7 -1
  65. package/dist/types/model/classifier/baseten.d.ts +8 -0
  66. package/dist/types/model/classifier/credentials.d.ts +2 -0
  67. package/dist/types/model/classifier/jev.d.ts +9 -0
  68. package/dist/types/model/classifier/profile.d.ts +3 -1
  69. package/dist/types/model/classifier/profileExecution.d.ts +2 -1
  70. package/dist/types/model/classifier/providers.d.ts +30 -6
  71. package/dist/types/model/classifier/questionHelpers.d.ts +3 -1
  72. package/dist/types/model/classifier/questions.d.ts +2 -1
  73. package/dist/types/model/classifier/state.d.ts +1 -0
  74. package/dist/types/model/classifier/subq.d.ts +8 -0
  75. package/dist/types/model/classifier/types.d.ts +9 -2
  76. package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +2 -4
  77. package/dist/types/model/nodes/ClassifierQuestionNode.d.ts +2 -2
  78. package/dist/types/model/tokenPricing.d.ts +18 -0
  79. package/dist/types/model/tokenPricingEditor.d.ts +4 -0
  80. package/package.json +2 -2
@@ -1,27 +1,57 @@
1
1
  import { assertClassifierEntryKind, assertClassifierInstructionsKind, snapshotClassifierJson, classifierArrayValues, } from './json.js';
2
+ import { inspectStateMessages, systemOneState } from './state.js';
3
+ export function createQuestionMap(questions, instructionsFor = (question) => question.instructionsMessages
4
+ ? systemOneState({ state: '', stateMessages: question.instructionsMessages }).state
5
+ : question.instructions) {
6
+ const result = Object.create(null);
7
+ for (const question of questions) {
8
+ const instructions = instructionsFor(question);
9
+ const providerQuestion = (question.type === 'noul' || question.type === 'box') && question.criteria === undefined
10
+ ? { type: question.type, instructions }
11
+ : { type: question.type, instructions, criteria: question.criteria };
12
+ Object.defineProperty(result, question.questionId, { enumerable: true, value: providerQuestion });
13
+ }
14
+ return result;
15
+ }
2
16
  /** Shared by node execution and direct provider calls, before taking the request snapshot. */
3
17
  export function prepareClassifierQuestion(value, budget) {
4
18
  if (value === null || typeof value !== 'object' || Array.isArray(value))
5
19
  throw new Error('Question inputs must contain question definition objects.');
6
20
  if ('images' in value)
7
- throw new Error("Question-level images are not supported. Connect images to Classifier Evaluate's State input.");
21
+ throw new Error("Question-level images fields are not supported. Connect images to Question Instructions (Jev/OpenAI), or to Decision AI run's State input for shared evidence.");
22
+ if ('instructionsMessages' in value) {
23
+ const descriptor = Object.getOwnPropertyDescriptor(value, 'instructionsMessages');
24
+ if (!descriptor?.enumerable || !('value' in descriptor))
25
+ throw new Error('Question instructionsMessages must be an own, enumerable data field.');
26
+ }
8
27
  for (const key of ['questionId', 'type', 'instructions']) {
9
28
  if (!Object.prototype.propertyIsEnumerable.call(value, key))
10
- throw new Error(`Every classifier question must have an own, enumerable '${key}' field.`);
29
+ throw new Error(`Every Decision AI question must have an own, enumerable '${key}' field.`);
11
30
  }
12
31
  const criteriaProperty = Object.getOwnPropertyDescriptor(value, 'criteria');
13
32
  if (criteriaProperty && (!criteriaProperty.enumerable || !('value' in criteriaProperty)))
14
- throw new Error('Classifier question criteria must be an own, enumerable field.');
33
+ throw new Error('Decision AI question criteria must be an own, enumerable field.');
15
34
  // Optional envelope properties may be undefined; structured entries themselves must be exact JSON.
16
35
  const question = snapshotClassifierJson(value, 'Question', budget, true);
17
36
  if (typeof question.questionId !== 'string' || question.questionId.trim() === '')
18
- throw new Error('Every classifier question must have a non-empty Question ID.');
19
- if (!['choice', 'score', 'noul'].includes(question.type))
37
+ throw new Error('Every Decision AI question must have a non-empty Question ID.');
38
+ if (!['choice', 'score', 'noul', 'box'].includes(question.type))
20
39
  throw new Error(`Question '${question.questionId}' has an unsupported type.`);
21
40
  // The whole question has already passed recursive JSON/resource validation.
22
41
  // Check only entry kinds here; do not scan each structured entry again.
23
- assertClassifierInstructionsKind(question.instructions, `Question '${question.questionId}' instructions`);
42
+ if (question.instructionsMessages !== undefined) {
43
+ if (question.instructions !== '')
44
+ throw new Error('Question instructions and instructionsMessages cannot be supplied together.');
45
+ inspectStateMessages(question.instructionsMessages, budget.check);
46
+ if (!question.instructionsMessages.some(({ parts }) => parts.some((part) => part.type === 'image' || part.text.trim() !== '')))
47
+ throw new Error(`Question '${question.questionId}' instructions must not be empty.`);
48
+ }
49
+ else {
50
+ assertClassifierInstructionsKind(question.instructions, `Question '${question.questionId}' instructions`);
51
+ }
24
52
  const criteria = question.criteria;
53
+ if (question.type === 'box' && criteria !== undefined)
54
+ throw new Error(`Bounding Box question '${question.questionId}' does not accept criteria.`);
25
55
  if (question.type === 'choice') {
26
56
  if (typeof criteria !== 'object' || criteria === null || Array.isArray(criteria))
27
57
  throw new Error(`Choice question '${question.questionId}' requires object criteria.`);
@@ -38,7 +68,7 @@ export function prepareClassifierQuestion(value, budget) {
38
68
  for (const entry of classifierArrayValues(criteria, 'Criteria'))
39
69
  assertClassifierEntryKind(entry, `Question '${question.questionId}' criteria[${index++}]`);
40
70
  }
41
- else if (criteria !== undefined) {
71
+ else if (question.type === 'noul' && criteria !== undefined) {
42
72
  if (typeof criteria !== 'object' ||
43
73
  criteria === null ||
44
74
  Array.isArray(criteria) ||
@@ -27,11 +27,11 @@ function requireProbabilityMap(value, keys, label, providerLabel) {
27
27
  for (const key of keys)
28
28
  requireResponseNumber(probabilities[key], `${label}.${key}`, providerLabel);
29
29
  }
30
- export function validateApiCompatibleClassifierResponse(body, questions, providerLabel = 'Classifier provider') {
30
+ export function validateApiCompatibleClassifierResponse(body, questions, providerLabel = 'Decision AI provider') {
31
31
  return validateClassifierEvaluationResponse(body, questions, providerLabel);
32
32
  }
33
33
  /** Validate the common Rivet result, independently of the provider's wire protocol. */
34
- export function validateClassifierEvaluationResponse(body, questions, providerLabel = 'Classifier provider') {
34
+ export function validateClassifierEvaluationResponse(body, questions, providerLabel = 'Decision AI provider') {
35
35
  const model = isRecord(body) ? responseField(body, 'model') : undefined;
36
36
  const answers = isRecord(body) ? responseField(body, 'answers') : undefined;
37
37
  const usage = isRecord(body) ? responseField(body, 'usage') : undefined;
@@ -65,6 +65,12 @@ export function validateClassifierEvaluationResponse(body, questions, providerLa
65
65
  requireProbabilityMap(responseField(answer, 'probabilities'), keys, `${question.questionId}.probabilities`, providerLabel);
66
66
  requireResponseMap(responseField(answer, 'legend'), keys, `${question.questionId}.legend`, providerLabel);
67
67
  }
68
+ else if (question.type === 'box') {
69
+ const box = requireResponseMap(responseField(answer, 'box'), ['top', 'bottom', 'left', 'right'], `${question.questionId}.box`, providerLabel);
70
+ for (const edge of ['top', 'bottom', 'left', 'right'])
71
+ requireResponseNumber(box[edge], `${question.questionId}.box.${edge}`, providerLabel);
72
+ requireResponseNumber(responseField(answer, 'confidence'), `${question.questionId}.confidence`, providerLabel);
73
+ }
68
74
  else {
69
75
  requireResponseNumber(responseField(answer, 'noul'), `${question.questionId}.noul`, providerLabel);
70
76
  }
@@ -140,7 +140,7 @@ function prepareRivetState(input, budget) {
140
140
  }
141
141
  else if (message(item)) {
142
142
  if (classifierDataProperty(item, 'type') !== 'user' || 'function_call' in item || 'function_calls' in item)
143
- throw new Error('Classifier State supports only user messages, not system, developer, assistant, or tool messages.');
143
+ throw new Error('Decision AI State supports only user messages, not system, developer, assistant, or tool messages.');
144
144
  flush();
145
145
  if (messages.length >= CLASSIFIER_LIMITS.messages)
146
146
  throw new Error('State has too many messages.');
@@ -161,7 +161,7 @@ function prepareRivetState(input, budget) {
161
161
  flush();
162
162
  return messages.length ? { kind: 'messages', messages, images } : { kind: 'json', value: '' };
163
163
  }
164
- function inspectStateMessages(messages, check) {
164
+ export function inspectStateMessages(messages, check) {
165
165
  if (!Array.isArray(messages))
166
166
  throw new Error('State messages must be an array.');
167
167
  if (messages.length > CLASSIFIER_LIMITS.messages)
@@ -0,0 +1,51 @@
1
+ import { systemOneState } from './state.js';
2
+ /** https://docs.subq.ai/using-the-api/models/ (verified 2026-10-24). */
3
+ export const SUBQ_DECISION_MODELS = ['subq-snap-1.1'];
4
+ /** SubQ separates images from State and requires typed, bare-base64 objects. */
5
+ export function subqDecisionState(state) {
6
+ if (state.kind === 'json')
7
+ return { state: state.value };
8
+ const wire = systemOneState({ state: '', stateMessages: state.messages });
9
+ return {
10
+ state: wire.state,
11
+ ...(state.images.length
12
+ ? {
13
+ images: state.images.map(({ mediaType, dataUrl }) => ({
14
+ mediaType,
15
+ base64: dataUrl.slice(dataUrl.indexOf(',') + 1),
16
+ })),
17
+ }
18
+ : {}),
19
+ };
20
+ }
21
+ /** Capability failures allow profile fallback without silently dropping/splitting evidence. */
22
+ export function assertSubQDecisionLimits({ state, questions }, check) {
23
+ if (questions.length > 128)
24
+ throw new Error('SubQ Snap supports at most 128 questions per request.');
25
+ for (const question of questions) {
26
+ // JSON Schema string lengths count Unicode code points, not UTF-16 units.
27
+ let characters = 0;
28
+ for (const _character of question.questionId) {
29
+ check();
30
+ if (++characters > 100)
31
+ throw new Error('SubQ Snap question IDs must contain at most 100 characters.');
32
+ }
33
+ }
34
+ if (state.kind !== 'messages')
35
+ return;
36
+ if (state.images.length > 4)
37
+ throw new Error('SubQ Snap supports at most 4 images per request.');
38
+ let total = 0;
39
+ for (const { mediaType, dataUrl } of state.images) {
40
+ check();
41
+ if (!['image/png', 'image/jpeg', 'image/webp'].includes(mediaType))
42
+ throw new Error('SubQ Snap accepts PNG, JPEG and WebP images, not GIF.');
43
+ const payload = dataUrl.slice(dataUrl.indexOf(',') + 1);
44
+ const bytes = (payload.length / 4) * 3 - (payload.endsWith('==') ? 2 : payload.endsWith('=') ? 1 : 0);
45
+ if (bytes > 4 * 1024 * 1024)
46
+ throw new Error('SubQ Snap images must not exceed 4 MiB decoded each.');
47
+ total += bytes;
48
+ }
49
+ if (total > 8 * 1024 * 1024)
50
+ throw new Error('SubQ Snap images must not exceed 8 MiB decoded in total.');
51
+ }
@@ -8,7 +8,9 @@ import { getNextVariadicPortIndex } from './variadicPortIndex.js';
8
8
  import { resolveClassifierApiKey } from '../classifier/credentials.js';
9
9
  import { classifierArrayValues, classifierInputDataValue } from '../classifier/json.js';
10
10
  import { normalizeClassifierState } from '../classifier/state.js';
11
- import { CLASSIFIER_LIMITS, classifierPreparationCheck, ClassifierValueBudget } from '../classifier/limits.js';
11
+ import { validateTokenPricing } from '../tokenPricing.js';
12
+ import { getTokenPricingEditor } from '../tokenPricingEditor.js';
13
+ import { CLASSIFIER_LIMITS, ClassifierValueBudget } from '../classifier/limits.js';
12
14
  import { calculateClassifierUsageCost, classifierFailureKind, classifierProviders, DEFAULT_CLASSIFIER_RETRY_ON_NON_200_COOLDOWN_MS, DEFAULT_CLASSIFIER_RETRY_ON_NON_200_REPEAT_TIMES, getClassifierProvider, normalizeClassifierNon200RetryCooldownMs, normalizeClassifierNon200RetryCount, } from '../classifier/providers.js';
13
15
  import { normalizeClassifierProfiles } from '../classifier/profile.js';
14
16
  import { classifierProfileSummary, ClassifierProfileExhaustedError, runClassifierProfiles, } from '../classifier/profileExecution.js';
@@ -21,13 +23,13 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
21
23
  static create() {
22
24
  return {
23
25
  type: 'classifierEvaluate',
24
- title: 'Classifier Evaluate',
26
+ title: 'Decision AI run',
25
27
  id: nanoid(),
26
28
  visualData: { x: 0, y: 0, width: 260 },
27
29
  // Keep the default model in the provider descriptor rather than
28
30
  // serializing Jev's model into every new node. A future provider then
29
31
  // receives its own default when an author changes the Provider field.
30
- data: { provider: 'jev', timeoutMs: 30_000, errorOnNon200: true, catchRequestFailed: false },
32
+ data: { provider: 'jev', errorOnNon200: true, catchRequestFailed: false },
31
33
  };
32
34
  }
33
35
  getInputDefinitions(connections) {
@@ -55,12 +57,12 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
55
57
  if (this.data.configurationMode === 'profile') {
56
58
  inputs.unshift({
57
59
  id: 'classifierProfile',
58
- title: 'Classifier Profiles',
60
+ title: 'Decision AI Profiles',
59
61
  dataType: ['classifier-config', 'classifier-config[]'],
60
62
  required: true,
61
63
  coerced: true,
62
64
  splitRunBehavior: 'preserve-array',
63
- description: 'One Classifier Profile or an ordered fallback chain.',
65
+ description: 'One Decision AI Profile or an ordered fallback chain.',
64
66
  });
65
67
  }
66
68
  if (this.data.configurationMode !== 'profile' && this.data.useModelInput) {
@@ -99,11 +101,11 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
99
101
  outputs.push({ id: 'responseBody', title: 'Response body', dataType: 'object' });
100
102
  }
101
103
  if (this.data.outputClassifierAttempts)
102
- outputs.push({ id: 'classifierAttempts', title: 'Classifier Attempts', dataType: 'object[]' });
104
+ outputs.push({ id: 'classifierAttempts', title: 'Decision AI Attempts', dataType: 'object[]' });
103
105
  if (this.data.configurationMode === 'profile' && this.data.outputClassifierProfileSummary)
104
106
  outputs.push({
105
107
  id: 'classifierProfileSummary',
106
- title: 'Classifier Profile Summary',
108
+ title: 'Decision AI Profile Summary',
107
109
  dataType: 'string',
108
110
  });
109
111
  return [...outputs, ...getRunFailureOutputDefinitions({ catchRequestFailed: this.data.catchRequestFailed })];
@@ -111,7 +113,11 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
111
113
  getEditors() {
112
114
  return [
113
115
  { type: 'custom', label: 'Configuration', customEditorId: 'ClassifierConfiguration' },
114
- { ...getClassifierModelEditor(this.data), hideIf: (data) => data.configurationMode === 'profile' },
116
+ { ...getClassifierModelEditor(), hideIf: (data) => data.configurationMode === 'profile' },
117
+ {
118
+ ...getTokenPricingEditor(),
119
+ hideIf: (data) => data.configurationMode === 'profile',
120
+ },
115
121
  {
116
122
  type: 'group',
117
123
  label: 'Outputs',
@@ -120,13 +126,13 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
120
126
  type: 'toggle',
121
127
  label: 'Usage details',
122
128
  dataKey: 'outputUsage',
123
- helperMessage: 'Adds estimated totalCost to Usage only for recognized requested/returned models. Unknown pricing is omitted. Provider-specific premiums are not included.',
129
+ helperMessage: 'Adds estimated totalCost to Usage using explicit token prices or known model rates. Unknown pricing is omitted. Provider-specific premiums are not included.',
124
130
  },
125
131
  {
126
132
  type: 'toggle',
127
133
  label: 'Request body',
128
134
  dataKey: 'outputRequestBody',
129
- helperMessage: 'Adds the exact classifier request JSON body sent to the provider. It excludes authorization headers and Rivet-managed API keys.',
135
+ helperMessage: 'Adds the exact Decision AI request JSON body sent to the provider. It excludes authorization headers and Rivet-managed API keys.',
130
136
  },
131
137
  {
132
138
  type: 'toggle',
@@ -134,31 +140,15 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
134
140
  dataKey: 'outputResponseBody',
135
141
  helperMessage: 'Shows the provider response, including rejected or invalid responses. Non-JSON responses appear as raw text. Captured content may contain sensitive input.',
136
142
  },
137
- { type: 'toggle', label: 'Classifier attempts', dataKey: 'outputClassifierAttempts' },
143
+ { type: 'toggle', label: 'Decision AI attempts', dataKey: 'outputClassifierAttempts' },
138
144
  {
139
145
  type: 'toggle',
140
- label: 'Classifier profile summary',
146
+ label: 'Decision AI profile summary',
141
147
  dataKey: 'outputClassifierProfileSummary',
142
148
  hideIf: (data) => data.configurationMode !== 'profile',
143
149
  },
144
150
  ],
145
151
  },
146
- {
147
- type: 'group',
148
- label: 'Advanced',
149
- editors: [
150
- {
151
- type: 'number',
152
- label: 'Overall timeout (seconds)',
153
- dataKey: this.data.configurationMode === 'profile' ? 'profileChainTimeoutMs' : 'timeoutMs',
154
- defaultValue: this.data.configurationMode === 'profile' ? 180_000 : 30_000,
155
- storageMultiplier: 1000,
156
- min: 1_000,
157
- max: 600_000,
158
- step: 1_000,
159
- },
160
- ],
161
- },
162
152
  {
163
153
  type: 'group',
164
154
  label: 'Error behavior',
@@ -223,10 +213,10 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
223
213
  }
224
214
  static getUIData() {
225
215
  return {
226
- contextMenuTitle: 'Classifier Evaluate',
227
- infoBoxTitle: 'Classifier Evaluate',
228
- infoBoxBody: 'Evaluates shared state and optional images against typed classifier questions. Images are shared evidence for every question.',
229
- group: ['Classifier'],
216
+ contextMenuTitle: 'Decision AI run',
217
+ infoBoxTitle: 'Decision AI run',
218
+ infoBoxBody: 'Evaluates shared state and optional images against typed Decision AI questions. Images are shared evidence for every question.',
219
+ group: ['Decision AI'],
230
220
  };
231
221
  }
232
222
  async process(inputs, context) {
@@ -299,15 +289,12 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
299
289
  if (this.data.configurationMode !== undefined &&
300
290
  this.data.configurationMode !== 'inline' &&
301
291
  this.data.configurationMode !== 'profile')
302
- throw new Error('Unknown classifier configuration mode.');
303
- const timeoutMs = this.data.configurationMode === 'profile'
304
- ? normalizeTimeout(this.data.profileChainTimeoutMs ?? 180_000)
305
- : normalizeTimeout(this.data.timeoutMs);
306
- const deadline = Date.now() + timeoutMs;
307
- const checkPreparation = classifierPreparationCheck(context.signal, deadline, timeoutMs);
292
+ throw new Error('Unknown Decision AI configuration mode.');
293
+ const checkPreparation = () => context.signal.throwIfAborted();
308
294
  checkPreparation();
309
295
  if (this.data.configurationMode === 'profile')
310
- return this.processProfiles(inputs, context, deadline, checkPreparation, attempts, diagnostics);
296
+ return this.processProfiles(inputs, context, checkPreparation, attempts, diagnostics);
297
+ const tokenPricing = validateTokenPricing(this.data.tokenPricing);
311
298
  const provider = getClassifierProvider(this.data.provider);
312
299
  if (!provider.browserExecutionSupported && context.executor === 'browser') {
313
300
  throw new Error(`${provider.label} cannot run in the Browser executor. Select the Node executor, or run through Studio Server or remote debugging.`);
@@ -354,9 +341,10 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
354
341
  }
355
342
  }
356
343
  if (questions.length === 0)
357
- throw new Error('Classifier Evaluate requires at least one question.');
344
+ throw new Error('Decision AI run requires at least one question.');
358
345
  const result = await (provider.evaluateInput ?? provider.evaluate).call(provider, {
359
346
  apiKey,
347
+ tokenPricing,
360
348
  model: modelValue,
361
349
  questions,
362
350
  retryOnNon200: this.data.retryOnNon200,
@@ -364,8 +352,6 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
364
352
  retryOnNon200RepeatTimes: this.data.retryOnNon200RepeatTimes,
365
353
  signal: context.signal,
366
354
  ...state,
367
- timeoutMs,
368
- deadline,
369
355
  ...diagnostics,
370
356
  onAttempt: ({ kind, ...attempt }) => {
371
357
  const event = {
@@ -387,16 +373,18 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
387
373
  });
388
374
  },
389
375
  });
390
- // Custom providers still own their asynchronous transport, but no late
391
- // result may become a successful node output after the original deadline.
376
+ // Custom providers own their transport; caller cancellation still wins.
392
377
  checkPreparation();
393
- return { ...this.projectResult(provider, modelValue, result, checkPreparation), ...this.profileEvidence(attempts) };
378
+ return {
379
+ ...this.projectResult(provider, modelValue, result, checkPreparation, tokenPricing),
380
+ ...this.profileEvidence(attempts),
381
+ };
394
382
  }
395
- projectResult(provider, modelValue, result, checkPreparation) {
383
+ projectResult(provider, modelValue, result, checkPreparation, tokenPricing) {
396
384
  const totalCost = calculateClassifierUsageCost(provider, result.response.usage, {
397
385
  requestedModel: modelValue,
398
386
  responseModel: result.response.model,
399
- });
387
+ }, tokenPricing);
400
388
  // The provider's parsed response may also be exposed verbatim through the
401
389
  // diagnostic output. Do not mutate its Usage object while adding Rivet's
402
390
  // calculated accounting detail.
@@ -430,7 +418,7 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
430
418
  : {}),
431
419
  };
432
420
  }
433
- async processProfiles(inputs, context, deadline, check, attempts, diagnostics) {
421
+ async processProfiles(inputs, context, check, attempts, diagnostics) {
434
422
  const profiles = normalizeClassifierProfiles(classifierInputDataValue(inputs, 'classifierProfile')?.value, check);
435
423
  const graph = context.project?.graphs[context.execution?.graphId];
436
424
  if (classifierInputDataValue(inputs, 'images') !== undefined ||
@@ -449,7 +437,7 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
449
437
  flattenQuestions(input.value, values, check, new Set(), 0, work);
450
438
  }
451
439
  if (!values.length)
452
- throw new Error('Classifier Evaluate requires at least one question.');
440
+ throw new Error('Decision AI run requires at least one question.');
453
441
  const ids = new Set();
454
442
  const questions = values.map((value) => {
455
443
  const question = prepareClassifierQuestion(value, budget);
@@ -464,7 +452,6 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
464
452
  questions,
465
453
  context,
466
454
  nodeId: this.chartNode.id,
467
- deadline,
468
455
  retryOnNon200: this.data.retryOnNon200,
469
456
  retryOnNon200RepeatTimes: this.data.retryOnNon200RepeatTimes,
470
457
  retryOnNon200CooldownMs: this.data.retryOnNon200CooldownMs,
@@ -481,13 +468,13 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
481
468
  });
482
469
  check();
483
470
  return {
484
- ...this.projectResult(selected.provider, selected.model, selected.result, check),
471
+ ...this.projectResult(selected.provider, selected.model, selected.result, check, selected.tokenPricing),
485
472
  ...this.profileEvidence(attempts, classifierProfileSummary(profiles, attempts)),
486
473
  };
487
474
  }
488
475
  }
489
476
  /** Shared settings definition; constructing an unrelated node is unnecessary. */
490
- export function getClassifierModelEditor(data) {
477
+ export function getClassifierModelEditor() {
491
478
  return {
492
479
  type: 'group',
493
480
  label: 'Model',
@@ -501,11 +488,11 @@ export function getClassifierModelEditor(data) {
501
488
  options: classifierProviders.map((provider) => ({ value: provider.id, label: provider.label })),
502
489
  },
503
490
  {
504
- type: 'string',
491
+ type: 'custom',
505
492
  label: 'Model',
506
493
  dataKey: 'model',
507
494
  useInputToggleDataKey: 'useModelInput',
508
- placeholder: getProviderForDisplay(data.provider).defaultModel,
495
+ customEditorId: 'ClassifierModel',
509
496
  },
510
497
  {
511
498
  type: 'segmented',
@@ -515,7 +502,7 @@ export function getClassifierModelEditor(data) {
515
502
  defaultValue: 'configured',
516
503
  options: [
517
504
  { value: 'configured', label: 'Automatic' },
518
- { value: 'classifier-settings', label: 'Classifier settings' },
505
+ { value: 'classifier-settings', label: 'Decision AI settings' },
519
506
  { value: 'input', label: 'Input port' },
520
507
  ],
521
508
  helperMessage: getApiKeySourceHelperMessage,
@@ -540,7 +527,7 @@ function getProviderForDisplay(id) {
540
527
  function getStaticModel(model, defaultModel) {
541
528
  return typeof model === 'string' && model.trim() !== '' ? model.trim() : defaultModel;
542
529
  }
543
- /** Shared presentation model for the app's Classifier Evaluate card. */
530
+ /** Shared presentation model for the app's Decision AI run card. */
544
531
  export function getClassifierEvaluateBodySections(data) {
545
532
  const provider = getProviderForDisplay(data.provider);
546
533
  const sections = [
@@ -588,8 +575,8 @@ function getApiKeySourceHelperMessage(data) {
588
575
  return 'Uses the API Key input port instead of a configured provider key.';
589
576
  const provider = getProviderForDisplay(data.provider);
590
577
  if (data.apiKeySource === 'classifier-settings')
591
- return `Uses only Settings > Classifier > ${provider.label} API Key on the executor. Does not fall back to named or environment credentials.`;
592
- return 'Automatic checks the named programmatic setting, then the named environment variable, then the saved Classifier key (default names only). OpenAI also accepts its legacy general key; Jev accepts its legacy plugin key last. Resolution happens on the executor, not in this editor.';
578
+ return `Uses only Settings > Decision AI > ${provider.label} API Key on the executor. Does not fall back to named or environment credentials.`;
579
+ return 'Automatic checks the named programmatic setting, then the named environment variable, then the saved Decision AI key (default names only). OpenAI also accepts its legacy general key; Jev accepts its legacy plugin key last. Resolution happens on the executor, not in this editor.';
593
580
  }
594
581
  function flattenQuestions(value, target, check, seen = new Set(), depth = 0, work = { values: 0 }) {
595
582
  check();
@@ -602,7 +589,7 @@ function flattenQuestions(value, target, check, seen = new Set(), depth = 0, wor
602
589
  throw new Error('Question inputs must not contain circular arrays.');
603
590
  seen.add(value);
604
591
  if (value.length > CLASSIFIER_LIMITS.questions)
605
- throw new Error('Classifier Evaluate supports at most 1000 questions.');
592
+ throw new Error('Decision AI run supports at most 1000 questions.');
606
593
  for (const item of classifierArrayValues(value, 'Questions'))
607
594
  flattenQuestions(item, target, check, seen, depth + 1, work);
608
595
  seen.delete(value);
@@ -612,12 +599,7 @@ function flattenQuestions(value, target, check, seen = new Set(), depth = 0, wor
612
599
  throw new Error('Question inputs must contain question definition objects or nested arrays of definitions.');
613
600
  }
614
601
  if (target.length >= CLASSIFIER_LIMITS.questions)
615
- throw new Error('Classifier Evaluate supports at most 1000 questions.');
602
+ throw new Error('Decision AI run supports at most 1000 questions.');
616
603
  target.push(value);
617
604
  }
618
- function normalizeTimeout(timeoutMs) {
619
- return typeof timeoutMs === 'number' && Number.isFinite(timeoutMs) && timeoutMs > 0
620
- ? Math.min(timeoutMs, 600_000)
621
- : 30_000;
622
- }
623
- export const classifierEvaluateNode = nodeDefinition(ClassifierEvaluateNodeImpl, 'Classifier Evaluate');
605
+ export const classifierEvaluateNode = nodeDefinition(ClassifierEvaluateNodeImpl, 'Decision AI run');
@@ -5,11 +5,12 @@ import { resolveClassifierProfile, DEFAULT_CLASSIFIER_PROFILE_RESPONSE_TIMEOUT_M
5
5
  import { getClassifierModelEditor, getClassifierEvaluateBodySections } from './ClassifierEvaluateNode.js';
6
6
  import { formatNodeBodyMarkdownField } from '../nodeBodyMarkdown.js';
7
7
  import { profileSuspensionHints } from '../profileSuspensionHints.js';
8
+ import { getTokenPricingEditor } from '../tokenPricingEditor.js';
8
9
  export class ClassifierProfileNodeImpl extends NodeImpl {
9
10
  static create() {
10
11
  return {
11
12
  type: 'classifierProfile',
12
- title: 'Classifier Profile',
13
+ title: 'Decision AI Profile',
13
14
  id: nanoid(),
14
15
  visualData: { x: 0, y: 0, width: 260 },
15
16
  data: { provider: 'jev', responseTimeoutMs: DEFAULT_CLASSIFIER_PROFILE_RESPONSE_TIMEOUT_MS },
@@ -31,16 +32,17 @@ export class ClassifierProfileNodeImpl extends NodeImpl {
31
32
  id: 'profile',
32
33
  title: 'Profile',
33
34
  dataType: 'classifier-config',
34
- description: 'Sensitive resolved classifier configuration. Combine profiles with Array for ordered fallback.',
35
+ description: 'Sensitive resolved Decision AI configuration. Combine profiles with Array for ordered fallback.',
35
36
  },
36
37
  ];
37
38
  }
38
39
  getEditors() {
39
40
  return [
40
- getClassifierModelEditor(this.data),
41
+ getClassifierModelEditor(),
42
+ getTokenPricingEditor(),
41
43
  {
42
44
  type: 'group',
43
- label: 'Classifier profile suspension',
45
+ label: 'Decision AI profile suspension',
44
46
  editors: [
45
47
  {
46
48
  type: 'info',
@@ -117,10 +119,10 @@ export class ClassifierProfileNodeImpl extends NodeImpl {
117
119
  }
118
120
  static getUIData() {
119
121
  return {
120
- contextMenuTitle: 'Classifier Profile',
121
- infoBoxTitle: 'Classifier Profile',
122
- infoBoxBody: 'Reusable classifier provider/model/credential configuration. Combine profiles with Array for ordered fallback.',
123
- group: ['Classifier'],
122
+ contextMenuTitle: 'Decision AI Profile',
123
+ infoBoxTitle: 'Decision AI Profile',
124
+ infoBoxBody: 'Reusable Decision AI provider/model/credential configuration. Combine profiles with Array for ordered fallback.',
125
+ group: ['Decision AI'],
124
126
  };
125
127
  }
126
128
  async process(inputs, context) {
@@ -130,4 +132,4 @@ export class ClassifierProfileNodeImpl extends NodeImpl {
130
132
  };
131
133
  }
132
134
  }
133
- export const classifierProfileNode = nodeDefinition(ClassifierProfileNodeImpl, 'Classifier Profile');
135
+ export const classifierProfileNode = nodeDefinition(ClassifierProfileNodeImpl, 'Decision AI Profile');