@valerypopoff/rivet2-core 2.22.1 → 2.24.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 (49) hide show
  1. package/dist/cjs/bundle.cjs +1166 -797
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +4 -1
  4. package/dist/cjs/webAppRuntime.cjs.map +2 -2
  5. package/dist/esm/exports.js +0 -1
  6. package/dist/esm/index.js +3 -0
  7. package/dist/esm/integrations/CodeRunner.js +6 -3
  8. package/dist/esm/integrations/CodeRunnerNamespace.js +10 -0
  9. package/dist/esm/model/AgentResponseTracePresentation.js +5 -1
  10. package/dist/esm/model/ChildInvocationOwnership.js +51 -0
  11. package/dist/esm/model/GraphProcessor.js +32 -54
  12. package/dist/esm/model/NodeRegistration.js +2 -6
  13. package/dist/esm/model/classifier/baseten.js +78 -0
  14. package/dist/esm/model/classifier/credentials.js +17 -9
  15. package/dist/esm/model/classifier/images.js +4 -4
  16. package/dist/esm/model/classifier/jev.js +45 -0
  17. package/dist/esm/model/classifier/json.js +1 -1
  18. package/dist/esm/model/classifier/limits.js +13 -13
  19. package/dist/esm/model/classifier/openai.js +20 -2
  20. package/dist/esm/model/classifier/preparation.js +5 -5
  21. package/dist/esm/model/classifier/profile.js +14 -13
  22. package/dist/esm/model/classifier/profileExecution.js +26 -23
  23. package/dist/esm/model/classifier/providers.js +170 -74
  24. package/dist/esm/model/classifier/questionHelpers.js +21 -2
  25. package/dist/esm/model/classifier/questions.js +37 -7
  26. package/dist/esm/model/classifier/response.js +8 -2
  27. package/dist/esm/model/classifier/state.js +2 -2
  28. package/dist/esm/model/classifier/subq.js +51 -0
  29. package/dist/esm/model/nodes/ClassifierEvaluateNode.js +32 -61
  30. package/dist/esm/model/nodes/ClassifierProfileNode.js +9 -9
  31. package/dist/esm/model/nodes/ClassifierQuestionNode.js +53 -34
  32. package/dist/types/index.d.ts +1 -1
  33. package/dist/types/integrations/CodeRunner.d.ts +4 -1
  34. package/dist/types/integrations/CodeRunnerNamespace.d.ts +5 -0
  35. package/dist/types/model/AgentResponseTracePresentation.d.ts +2 -0
  36. package/dist/types/model/ChildInvocationOwnership.d.ts +36 -0
  37. package/dist/types/model/classifier/baseten.d.ts +8 -0
  38. package/dist/types/model/classifier/credentials.d.ts +2 -0
  39. package/dist/types/model/classifier/jev.d.ts +9 -0
  40. package/dist/types/model/classifier/profileExecution.d.ts +1 -1
  41. package/dist/types/model/classifier/providers.d.ts +26 -5
  42. package/dist/types/model/classifier/questionHelpers.d.ts +3 -1
  43. package/dist/types/model/classifier/questions.d.ts +2 -1
  44. package/dist/types/model/classifier/state.d.ts +1 -0
  45. package/dist/types/model/classifier/subq.d.ts +8 -0
  46. package/dist/types/model/classifier/types.d.ts +9 -2
  47. package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +2 -4
  48. package/dist/types/model/nodes/ClassifierQuestionNode.d.ts +2 -2
  49. package/package.json +2 -2
@@ -18,7 +18,17 @@ export function createOpenAIDecisionRequest(args) {
18
18
  ? state.value
19
19
  : JSON.stringify(state.value),
20
20
  questions: args.questions.map((question) => {
21
- const common = { name: question.questionId, instructions: text(question.instructions) };
21
+ if (question.type === 'box')
22
+ throw new Error('OpenAI Decisions does not support Bounding Box questions.');
23
+ const instructions = question.instructionsMessages
24
+ ? question.instructionsMessages.flatMap(({ parts }, index) => [
25
+ ...(index ? [{ type: 'input_text', text: '\n\n' }] : []),
26
+ ...parts.map((part) => part.type === 'text'
27
+ ? { type: 'input_text', text: part.text }
28
+ : { type: 'input_image', image_url: part.dataUrl }),
29
+ ])
30
+ : text(question.instructions);
31
+ const common = { name: question.questionId, instructions };
22
32
  if (question.type === 'choice')
23
33
  return {
24
34
  ...common,
@@ -39,7 +49,15 @@ export function createOpenAIDecisionRequest(args) {
39
49
  ...common,
40
50
  type: 'predicate',
41
51
  instructions: criteria
42
- ? `${common.instructions}\n\nTrue criterion: ${text(criteria.true)}\nFalse criterion: ${text(criteria.false)}`
52
+ ? typeof instructions === 'string'
53
+ ? `${instructions}\n\nTrue criterion: ${text(criteria.true)}\nFalse criterion: ${text(criteria.false)}`
54
+ : [
55
+ ...instructions,
56
+ {
57
+ type: 'input_text',
58
+ text: `\n\nTrue criterion: ${text(criteria.true)}\nFalse criterion: ${text(criteria.false)}`,
59
+ },
60
+ ]
43
61
  : common.instructions,
44
62
  };
45
63
  }),
@@ -13,7 +13,7 @@ export class ClassifierQuestionPreparation {
13
13
  check = () => {
14
14
  this.deadlineCheck();
15
15
  if (++this.operations > CLASSIFIER_LIMITS.values * 10)
16
- throw new ClassifierResourceLimitError('Classifier question preparation has too much expanded work.');
16
+ throw new ClassifierResourceLimitError('Decision AI question preparation has too much expanded work.');
17
17
  };
18
18
  capture(value) {
19
19
  this.inspect(value, false);
@@ -35,7 +35,7 @@ export class ClassifierQuestionPreparation {
35
35
  // Reject before concatenation. Exact UTF-8/JSON bytes are charged when
36
36
  // the completed entry is captured; this bounds intermediate allocations.
37
37
  if (fragment.length + previousLength > this.budget.remainingBytes)
38
- throw new ClassifierResourceLimitError('Classifier question interpolation exceeds its remaining byte budget.');
38
+ throw new ClassifierResourceLimitError('Decision AI question interpolation exceeds its remaining byte budget.');
39
39
  };
40
40
  processing = (input, name, parameter) => {
41
41
  this.check();
@@ -50,7 +50,7 @@ export class ClassifierQuestionPreparation {
50
50
  ((name === 'chain' || name === 'wrap') && nextWhitespace && !whitespace) ||
51
51
  (name !== 'chain' && name !== 'wrap' && input[i] === '\n')) {
52
52
  if (++pieces > CLASSIFIER_LIMITS.values)
53
- throw new ClassifierResourceLimitError('Classifier interpolation processor has too many expanded pieces.');
53
+ throw new ClassifierResourceLimitError('Decision AI interpolation processor has too many expanded pieces.');
54
54
  }
55
55
  whitespace = nextWhitespace;
56
56
  }
@@ -60,7 +60,7 @@ export class ClassifierQuestionPreparation {
60
60
  const value = parameter ?? (name === 'indent' ? 0 : 1);
61
61
  const prefix = name === 'indent' ? value : name === 'quote' ? value * 2 : (value - 1) * 2 + 2;
62
62
  if (!Number.isSafeInteger(value) || value < (name === 'list' ? 1 : 0))
63
- throw new Error(`Invalid classifier interpolation ${name} parameter.`);
63
+ throw new Error(`Invalid Decision AI interpolation ${name} parameter.`);
64
64
  let lines = 1;
65
65
  for (let i = 0; i < input.length; i++) {
66
66
  if ((i & 4095) === 0)
@@ -69,6 +69,6 @@ export class ClassifierQuestionPreparation {
69
69
  lines++;
70
70
  }
71
71
  if (input.length + lines * prefix > this.budget.remainingBytes)
72
- throw new ClassifierResourceLimitError('Classifier interpolation processor exceeds its remaining byte budget.');
72
+ throw new ClassifierResourceLimitError('Decision AI interpolation processor exceeds its remaining byte budget.');
73
73
  };
74
74
  }
@@ -28,7 +28,7 @@ export function pickClassifierProfileData(data) {
28
28
  function positive(value, fallback, label, maximum = 600_000) {
29
29
  const result = value ?? fallback;
30
30
  if (!Number.isSafeInteger(result) || result < 1 || result > maximum)
31
- throw new Error(`Classifier Profile ${label} must be an integer between 1 and ${maximum}.`);
31
+ throw new Error(`Decision AI Profile ${label} must be an integer between 1 and ${maximum}.`);
32
32
  return result;
33
33
  }
34
34
  export function classifierProfileResponseTimeout(configuration) {
@@ -45,7 +45,7 @@ export function classifierProfileHealthPolicy(configuration) {
45
45
  };
46
46
  }
47
47
  export function normalizeClassifierProfileValue(value) {
48
- return normalizeDetachedProfile(snapshotClassifierJson(value, 'Classifier Profile', new ClassifierValueBudget(), true));
48
+ return normalizeDetachedProfile(snapshotClassifierJson(value, 'Decision AI Profile', new ClassifierValueBudget(), true));
49
49
  }
50
50
  function normalizeDetachedProfile(value) {
51
51
  const profile = value;
@@ -57,30 +57,31 @@ function normalizeDetachedProfile(value) {
57
57
  !profile.credential ||
58
58
  typeof profile.credential !== 'object' ||
59
59
  Array.isArray(profile.credential))
60
- throw new Error('Classifier Profiles input requires a version 1 Classifier Profile.');
60
+ throw new Error('Decision AI Profiles input requires a version 1 Decision AI Profile.');
61
61
  const { configuration, credential } = profile;
62
62
  if (typeof configuration.provider !== 'string' ||
63
63
  typeof configuration.model !== 'string' ||
64
64
  !configuration.model.trim())
65
- throw new Error('Classifier Profile requires a provider and a nonblank model.');
65
+ throw new Error('Decision AI Profile requires a provider and a nonblank model.');
66
66
  getClassifierProvider(configuration.provider);
67
67
  if (credential.value !== undefined && (typeof credential.value !== 'string' || /[\r\n]/.test(credential.value)))
68
- throw new Error('Classifier Profile credential must be a string without line breaks.');
68
+ throw new Error('Decision AI Profile credential must be a string without line breaks.');
69
69
  if (profile.profileName !== undefined && typeof profile.profileName !== 'string')
70
- throw new Error('Invalid Classifier Profile name.');
70
+ throw new Error('Invalid Decision AI Profile name.');
71
71
  if (profile.sourceNodeId !== undefined && (typeof profile.sourceNodeId !== 'string' || !profile.sourceNodeId.trim()))
72
- throw new Error('Invalid Classifier Profile source node.');
72
+ throw new Error('Invalid Decision AI Profile source node.');
73
73
  if (configuration.enableCircuitBreaker !== undefined && typeof configuration.enableCircuitBreaker !== 'boolean')
74
- throw new Error('Classifier Profile automatic suspension must be a boolean.');
74
+ throw new Error('Decision AI Profile automatic suspension must be a boolean.');
75
75
  if (configuration.apiKeySource !== undefined &&
76
76
  !['configured', 'classifier-settings', 'input'].includes(configuration.apiKeySource))
77
- throw new Error('Unknown classifier API key source.');
77
+ throw new Error('Unknown Decision AI API key source.');
78
78
  classifierProfileResponseTimeout(configuration);
79
79
  classifierProfileHealthPolicy(configuration);
80
80
  return {
81
81
  version: 1,
82
82
  sourceNodeId: profile.sourceNodeId,
83
- profileName: profile.profileName?.trim() || undefined,
83
+ // Blank names are absent, but authored whitespace must survive exact-default display aliases.
84
+ profileName: profile.profileName?.trim() ? profile.profileName : undefined,
84
85
  credential: credential.value === undefined ? {} : { value: credential.value.trim() },
85
86
  configuration: {
86
87
  ...pickClassifierProfileData(configuration),
@@ -92,10 +93,10 @@ function normalizeDetachedProfile(value) {
92
93
  }
93
94
  export function normalizeClassifierProfiles(value, check) {
94
95
  if (Array.isArray(value) && (value.length === 0 || value.length > 128))
95
- throw new Error('Classifier Profiles requires between 1 and 128 profiles.');
96
+ throw new Error('Decision AI Profiles requires between 1 and 128 profiles.');
96
97
  // One deadline-aware traversal bounds, validates and detaches the whole
97
98
  // chain. Do not rescan each candidate with a fresh resource budget.
98
- const detached = snapshotClassifierJson(value, 'Classifier Profiles', new ClassifierValueBudget(check), true);
99
+ const detached = snapshotClassifierJson(value, 'Decision AI Profiles', new ClassifierValueBudget(check), true);
99
100
  return (Array.isArray(detached) ? detached : [detached]).map(normalizeDetachedProfile);
100
101
  }
101
102
  export function resolveClassifierProfile(data, inputs, context) {
@@ -104,7 +105,7 @@ export function resolveClassifierProfile(data, inputs, context) {
104
105
  ? classifierInputDataValue(inputs, 'model')?.value
105
106
  : data.model?.trim() || provider.defaultModel;
106
107
  if (typeof model !== 'string' || !model.trim())
107
- throw new Error('Classifier Profile model is required.');
108
+ throw new Error('Decision AI Profile model is required.');
108
109
  let value;
109
110
  // Missing credentials are a candidate failure, not an upstream graph failure.
110
111
  // Invalid credential-name configuration still fails while authoring the profile.
@@ -1,6 +1,7 @@
1
1
  import { createProfileHealthPermit, runBoundedHealthOperation, } from '../chat-v2/llmProfileFallback.js';
2
2
  import { ClassifierProviderError, classifierFailureKind, classifierErrorMessage, getClassifierProvider, } from './providers.js';
3
3
  import { classifierProfileHealthIdentity, classifierProfileHealthPolicy, classifierProfileResponseTimeout, } from './profile.js';
4
+ import { getProfileDisplayName } from '../AgentResponseTracePresentation.js';
4
5
  export function classifierProfileSummary(profiles, attempts) {
5
6
  return profiles
6
7
  .map((profile, index) => {
@@ -33,7 +34,7 @@ export function classifierProfileSummary(profiles, attempts) {
33
34
  outcome !== 'suspended' && healthState === 'open' ? '; profile is suspended' : '',
34
35
  healthState === 'half-open' ? '; recovery attempt in progress' : '',
35
36
  ].join('');
36
- return `${index + 1}. ${profile.profileName || 'Classifier Profile'} (${profile.configuration.provider}/${profile.configuration.model}): ${outcome}${details}`;
37
+ return `${index + 1}. ${getProfileDisplayName(profile.profileName, 'classifier') || 'Decision AI Profile'} (${profile.configuration.provider}/${profile.configuration.model}): ${outcome}${details}`;
37
38
  })
38
39
  .join('\n');
39
40
  }
@@ -45,23 +46,25 @@ export class ClassifierProfileExhaustedError extends Error {
45
46
  const details = attempts
46
47
  .filter((attempt) => attempt.outcome === 'failure' || attempt.outcome === 'aborted')
47
48
  .map((attempt) => {
48
- const profile = `Profile ${(attempt.profileIndex ?? 0) + 1}${attempt.profileName ? ` (${attempt.profileName})` : ''}`;
49
+ const profile = `Profile ${(attempt.profileIndex ?? 0) + 1}${attempt.profileName ? ` (${getProfileDisplayName(attempt.profileName, 'classifier')})` : ''}`;
49
50
  const request = attempt.attemptIndex === undefined ? '' : ` attempt ${attempt.attemptIndex + 1}`;
50
51
  const status = attempt.status === undefined ? '' : ` (HTTP ${attempt.status})`;
51
52
  const reason = attempt.error ? `: ${attempt.error.replace(/\r\n|\r|\n/g, '\n ')}` : '';
52
53
  return `${profile}, ${attempt.failureKind ?? attempt.stage}${request} ${attempt.outcome}${status}${reason}`;
53
54
  })
54
55
  .join('\n');
55
- super(`Classifier profile chain exhausted.\n${summary}${details ? `\n\nAttempt details:\n${details}` : ''}`, options);
56
+ super(`Decision AI profile chain exhausted.\n${summary}${details ? `\n\nAttempt details:\n${details}` : ''}`, options);
56
57
  this.attempts = attempts;
57
58
  this.summary = summary;
58
59
  this.statusCode = statusCode;
59
- this.name = 'ClassifierProfileExhaustedError';
60
+ // Human-visible error prefix only; the exported class and instanceof contract stay unchanged.
61
+ this.name = 'DecisionAIProfileExhaustedError';
60
62
  }
61
63
  }
62
64
  export async function runClassifierProfiles(input) {
63
65
  const attempts = [];
64
66
  const { context } = input;
67
+ const deadline = input.deadline ?? Infinity;
65
68
  let lastError;
66
69
  let httpFailuresOnly = true;
67
70
  let lastHttpStatus;
@@ -69,7 +72,7 @@ export async function runClassifierProfiles(input) {
69
72
  const event = {
70
73
  ...attempt,
71
74
  ...(attempt.stage === 'health-update' && attempt.outcome === 'failure'
72
- ? { error: 'Classifier profile health service unavailable.' }
75
+ ? { error: 'Decision AI profile health service unavailable.' }
73
76
  : {}),
74
77
  family: 'classifier',
75
78
  profileName: input.profiles[attempt.profileIndex ?? 0]?.profileName,
@@ -84,8 +87,8 @@ export async function runClassifierProfiles(input) {
84
87
  };
85
88
  for (let profileIndex = 0; profileIndex < input.profiles.length; profileIndex++) {
86
89
  context.signal.throwIfAborted();
87
- if (Date.now() >= input.deadline) {
88
- lastError = new ClassifierProviderError('Classifier overall deadline expired.', 'timeout');
90
+ if (Date.now() >= deadline) {
91
+ lastError = new ClassifierProviderError('Decision AI overall deadline expired.', 'timeout');
89
92
  const profile = input.profiles[profileIndex];
90
93
  record({
91
94
  roundIndex: 0,
@@ -95,7 +98,7 @@ export async function runClassifierProfiles(input) {
95
98
  stage: 'request',
96
99
  outcome: 'failure',
97
100
  failureKind: 'timeout',
98
- error: 'Classifier overall deadline expired.',
101
+ error: 'Decision AI overall deadline expired.',
99
102
  });
100
103
  httpFailuresOnly = false;
101
104
  break;
@@ -117,7 +120,7 @@ export async function runClassifierProfiles(input) {
117
120
  try {
118
121
  const begin = await runBoundedHealthOperation({
119
122
  operation: 'begin',
120
- timeoutMs: Math.max(1, Math.min(2000, input.deadline - Date.now())),
123
+ timeoutMs: Math.max(1, Math.min(2000, deadline - Date.now())),
121
124
  signal: context.signal,
122
125
  run: () => store.begin(health),
123
126
  onLateResolve: async (late) => {
@@ -133,7 +136,7 @@ export async function runClassifierProfiles(input) {
133
136
  healthDisposition: 'deny',
134
137
  healthState: begin.state,
135
138
  retryAt: begin.retryAt,
136
- error: 'Classifier profile is suspended.',
139
+ error: 'Decision AI profile is suspended.',
137
140
  });
138
141
  continue;
139
142
  }
@@ -166,29 +169,29 @@ export async function runClassifierProfiles(input) {
166
169
  stage: 'health-gate',
167
170
  outcome: 'failure',
168
171
  healthDisposition: 'fail-open',
169
- error: 'Classifier profile health service unavailable.',
172
+ error: 'Decision AI profile health service unavailable.',
170
173
  });
171
174
  }
172
175
  }
173
176
  try {
174
177
  context.signal.throwIfAborted();
175
178
  if (!provider.browserExecutionSupported && context.executor === 'browser')
176
- throw new ClassifierProviderError('Classifier provider requires the Node executor.', 'capability');
179
+ throw new ClassifierProviderError('Decision AI provider requires the Node executor.', 'capability');
177
180
  if (!profile.credential.value?.trim())
178
- throw new ClassifierProviderError('Classifier Profile API key is not set.', 'configuration');
179
- const remainingMs = input.deadline - Date.now();
181
+ throw new ClassifierProviderError('Decision AI Profile API key is not set.', 'configuration');
182
+ const remainingMs = deadline - Date.now();
180
183
  // Match LLM profiles: suspension deadlines require enabled, host-backed health.
181
184
  const timeoutMs = health
182
185
  ? Math.min(classifierProfileResponseTimeout(profile.configuration), remainingMs)
183
186
  : remainingMs;
184
187
  if (timeoutMs <= 0)
185
- throw new ClassifierProviderError('Classifier overall deadline expired.', 'timeout');
188
+ throw new ClassifierProviderError('Decision AI overall deadline expired.', 'timeout');
186
189
  const result = await provider.evaluate({
187
190
  ...input.state,
188
191
  questions: input.questions,
189
192
  apiKey: profile.credential.value,
190
193
  model,
191
- timeoutMs,
194
+ ...(Number.isFinite(timeoutMs) ? { timeoutMs } : {}),
192
195
  deadline: input.deadline,
193
196
  signal: context.signal,
194
197
  retryOnNon200: input.retryOnNon200,
@@ -210,12 +213,12 @@ export async function runClassifierProfiles(input) {
210
213
  },
211
214
  });
212
215
  context.signal.throwIfAborted();
213
- if (Date.now() >= input.deadline)
214
- throw new ClassifierProviderError('Classifier overall deadline expired.', 'timeout');
216
+ if (Date.now() >= deadline)
217
+ throw new ClassifierProviderError('Decision AI overall deadline expired.', 'timeout');
215
218
  await permit?.finish('healthy');
216
219
  context.signal.throwIfAborted();
217
- if (Date.now() >= input.deadline)
218
- throw new ClassifierProviderError('Classifier overall deadline expired.', 'timeout');
220
+ if (Date.now() >= deadline)
221
+ throw new ClassifierProviderError('Decision AI overall deadline expired.', 'timeout');
219
222
  for (let unreached = profileIndex + 1; unreached < input.profiles.length; unreached++) {
220
223
  const candidate = input.profiles[unreached];
221
224
  record({
@@ -271,9 +274,9 @@ export async function runClassifierProfiles(input) {
271
274
  (providerError.statusCode ?? 0) >= 500));
272
275
  await permit?.finish(!context.signal.aborted && observedRequest && unhealthy ? 'unhealthy' : 'ignored');
273
276
  context.signal.throwIfAborted();
274
- if (Date.now() >= input.deadline) {
277
+ if (Date.now() >= deadline) {
275
278
  httpFailuresOnly = false;
276
- lastError = new ClassifierProviderError('Classifier overall deadline expired.', 'timeout', undefined, {
279
+ lastError = new ClassifierProviderError('Decision AI overall deadline expired.', 'timeout', undefined, {
277
280
  cause: error,
278
281
  });
279
282
  if (providerError?.kind !== 'timeout')
@@ -281,7 +284,7 @@ export async function runClassifierProfiles(input) {
281
284
  ...base,
282
285
  stage: 'request',
283
286
  outcome: 'failure',
284
- error: 'Classifier overall deadline expired.',
287
+ error: 'Decision AI overall deadline expired.',
285
288
  failureKind: 'timeout',
286
289
  });
287
290
  break;