@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,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,30 @@ 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,
193
+ tokenPricing: profile.configuration.tokenPricing,
190
194
  model,
191
- timeoutMs,
195
+ ...(Number.isFinite(timeoutMs) ? { timeoutMs } : {}),
192
196
  deadline: input.deadline,
193
197
  signal: context.signal,
194
198
  retryOnNon200: input.retryOnNon200,
@@ -210,12 +214,12 @@ export async function runClassifierProfiles(input) {
210
214
  },
211
215
  });
212
216
  context.signal.throwIfAborted();
213
- if (Date.now() >= input.deadline)
214
- throw new ClassifierProviderError('Classifier overall deadline expired.', 'timeout');
217
+ if (Date.now() >= deadline)
218
+ throw new ClassifierProviderError('Decision AI overall deadline expired.', 'timeout');
215
219
  await permit?.finish('healthy');
216
220
  context.signal.throwIfAborted();
217
- if (Date.now() >= input.deadline)
218
- throw new ClassifierProviderError('Classifier overall deadline expired.', 'timeout');
221
+ if (Date.now() >= deadline)
222
+ throw new ClassifierProviderError('Decision AI overall deadline expired.', 'timeout');
219
223
  for (let unreached = profileIndex + 1; unreached < input.profiles.length; unreached++) {
220
224
  const candidate = input.profiles[unreached];
221
225
  record({
@@ -228,7 +232,7 @@ export async function runClassifierProfiles(input) {
228
232
  skipReason: 'unreached',
229
233
  });
230
234
  }
231
- return { result, provider, model };
235
+ return { result, provider, model, tokenPricing: profile.configuration.tokenPricing };
232
236
  }
233
237
  catch (error) {
234
238
  lastError = error;
@@ -271,9 +275,9 @@ export async function runClassifierProfiles(input) {
271
275
  (providerError.statusCode ?? 0) >= 500));
272
276
  await permit?.finish(!context.signal.aborted && observedRequest && unhealthy ? 'unhealthy' : 'ignored');
273
277
  context.signal.throwIfAborted();
274
- if (Date.now() >= input.deadline) {
278
+ if (Date.now() >= deadline) {
275
279
  httpFailuresOnly = false;
276
- lastError = new ClassifierProviderError('Classifier overall deadline expired.', 'timeout', undefined, {
280
+ lastError = new ClassifierProviderError('Decision AI overall deadline expired.', 'timeout', undefined, {
277
281
  cause: error,
278
282
  });
279
283
  if (providerError?.kind !== 'timeout')
@@ -281,7 +285,7 @@ export async function runClassifierProfiles(input) {
281
285
  ...base,
282
286
  stage: 'request',
283
287
  outcome: 'failure',
284
- error: 'Classifier overall deadline expired.',
288
+ error: 'Decision AI overall deadline expired.',
285
289
  failureKind: 'timeout',
286
290
  });
287
291
  break;