@outputai/core 0.15.1-dev.096a11c.0 → 0.15.1-dev.de5fa8c.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.
- package/dist/credentials/index.d.ts +1 -1
- package/dist/credentials/types.d.ts +4 -4
- package/dist/evals/aggregate.d.ts +2 -0
- package/dist/evals/aggregate.js +11 -0
- package/dist/evals/eval_workflow.d.ts +20 -0
- package/dist/evals/eval_workflow.js +98 -0
- package/dist/evals/index.d.ts +7 -0
- package/dist/evals/index.js +4 -0
- package/dist/evals/interpret.d.ts +3 -0
- package/dist/evals/interpret.js +40 -0
- package/dist/evals/schemas.d.ts +96 -0
- package/dist/evals/schemas.js +60 -0
- package/dist/evals/verdict.d.ts +27 -0
- package/dist/evals/verdict.js +109 -0
- package/dist/evals/verify.d.ts +42 -0
- package/dist/evals/verify.js +19 -0
- package/package.json +64 -14
- package/src/consts.d.ts +2 -0
- package/src/helpers/fetch.js +21 -9
- package/src/helpers/path.js +34 -0
- package/src/helpers/redact.js +2 -1
- package/src/http/config.js +10 -0
- package/src/http/cost.d.ts +20 -0
- package/src/http/cost.js +41 -0
- package/src/http/fetch/events.js +10 -0
- package/src/http/fetch/index.d.ts +24 -0
- package/src/http/fetch/index.js +78 -0
- package/src/http/fetch/logger.d.ts +10 -0
- package/src/http/fetch/logger.js +56 -0
- package/src/http/index.d.ts +28 -0
- package/src/http/index.js +9 -0
- package/src/http/ky/index.d.ts +25 -0
- package/src/http/ky/index.js +10 -0
- package/src/http/request_tag.js +30 -0
- package/src/interface/index.d.ts +1 -0
- package/src/llm/agent.js +147 -0
- package/src/llm/ai_provider.js +131 -0
- package/src/llm/ai_sdk_options.js +126 -0
- package/src/llm/consts.js +6 -0
- package/src/llm/deprecated_provider_aliases.js +8 -0
- package/src/llm/generate.js +98 -0
- package/src/llm/index.d.ts +697 -0
- package/src/llm/index.js +6 -0
- package/src/llm/judge.js +48 -0
- package/src/llm/prompt/content.js +70 -0
- package/src/llm/prompt/interpolations.js +58 -0
- package/src/llm/prompt/loader.js +67 -0
- package/src/llm/prompt/markup/attributes.js +52 -0
- package/src/llm/prompt/markup/nodes.js +71 -0
- package/src/llm/prompt/markup/tokenizer.js +3 -0
- package/src/llm/prompt/markup/tokens.js +26 -0
- package/src/llm/prompt/validations.js +129 -0
- package/src/llm/utils/cost.js +267 -0
- package/src/llm/utils/error_handler.js +53 -0
- package/src/llm/utils/file.js +42 -0
- package/src/llm/utils/google_vertex_auth.js +31 -0
- package/src/llm/utils/image.js +37 -0
- package/src/llm/utils/legacy_cost_attribute.js +75 -0
- package/src/llm/utils/metering.js +139 -0
- package/src/llm/utils/models.js +15 -0
- package/src/llm/utils/models_pricing.js +96 -0
- package/src/llm/utils/models_pricing_snapshot.json +4711 -0
- package/src/llm/utils/skills.js +74 -0
- package/src/llm/utils/sources.js +73 -0
- package/src/llm/utils/stream.js +75 -0
- package/src/llm/utils/tools.js +62 -0
- package/src/llm/utils/usage.js +155 -0
- package/src/llm/utils/usage_tools.js +23 -0
- package/src/llm/utils/web_search.js +155 -0
- package/src/llm/utils/wrap.js +279 -0
- package/src/llm/validations.js +234 -0
- package/src/tracing/trace_attribute.d.ts +0 -17
- package/src/tracing/trace_attribute.js +1 -29
- package/src/worker/bundler_options.js +1 -9
- package/src/worker/configs.js +23 -4
- package/src/worker/index.js +16 -47
- package/src/worker/interceptors/activity.js +0 -1
- package/src/worker/interceptors/workflow.js +0 -1
- package/src/worker/loader/workflows.js +16 -2
- package/src/worker/telemetry.js +122 -2
- package/src/worker/webpack_loaders/workflow_rewriter/index.mjs +3 -7
- package/src/worker/webpack_loaders/workflow_rewriter/rewrite_activity_calls.js +27 -7
- package/src/worker/webpack_loaders/workflow_validator/npm_workflow_export_resolve.js +5 -6
- package/src/worker/worker_options.js +43 -0
- package/src/sdk/README.md +0 -47
- package/src/sdk/helpers/component_metadata.d.ts +0 -17
- package/src/sdk/helpers/component_metadata.js +0 -6
- package/src/sdk/helpers/index.d.ts +0 -12
- package/src/sdk/helpers/index.js +0 -3
- package/src/sdk/helpers/objects.d.ts +0 -56
- package/src/sdk/helpers/objects.js +0 -8
- package/src/sdk/helpers/path.d.ts +0 -11
- package/src/sdk/helpers/path.js +0 -32
- package/src/sdk/runtime/context.d.ts +0 -30
- package/src/sdk/runtime/context.js +0 -15
- package/src/sdk/runtime/events.d.ts +0 -13
- package/src/sdk/runtime/events.js +0 -5
- package/src/sdk/runtime/index.d.ts +0 -12
- package/src/sdk/runtime/index.js +0 -3
- package/src/sdk/runtime/tracing.d.ts +0 -48
- package/src/sdk/runtime/tracing.js +0 -11
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Logger } from '#runtime_logger';
|
|
2
|
+
import { EnvHttpProxyAgent, fetch } from 'undici';
|
|
3
|
+
import modelsPricingSnapshot from './models_pricing_snapshot.json' with { type: 'json' };
|
|
4
|
+
|
|
5
|
+
const logger = Logger.createLogger( 'LLM' );
|
|
6
|
+
const costTableUrl = 'https://models.dev/api.json';
|
|
7
|
+
const cacheTTL = 1000 * 60 * 60 * 24; // 1 day
|
|
8
|
+
const cooldownTTL = 1000 * 60 * 10; // 10 minutes
|
|
9
|
+
|
|
10
|
+
/* Ignore HTTP/2. Check: https://github.com/growthxai/output/issues/299 */
|
|
11
|
+
const dispatcher = new EnvHttpProxyAgent( { allowH2: false } );
|
|
12
|
+
|
|
13
|
+
export const cache = {
|
|
14
|
+
content: null,
|
|
15
|
+
expiresAt: 0
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const Freshness = {
|
|
19
|
+
LIVE: 'live',
|
|
20
|
+
CACHED: 'cached',
|
|
21
|
+
STALE: 'stale',
|
|
22
|
+
SNAPSHOT: 'snapshot'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const state = {
|
|
26
|
+
ignoreLiveRequestsUntil: 0
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const parseData = data => {
|
|
30
|
+
const map = new Map();
|
|
31
|
+
try {
|
|
32
|
+
for ( const [ providerId, provider ] of Object.entries( data ) ) {
|
|
33
|
+
if ( providerId === '_meta' ) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for ( const [ modelName, { cost, reasoning } ] of Object.entries( provider.models ?? {} ) ) {
|
|
37
|
+
if ( cost ) { // some models don't have cost
|
|
38
|
+
map.set( `${providerId}/${modelName}`, {
|
|
39
|
+
cost,
|
|
40
|
+
reasoning: reasoning === true
|
|
41
|
+
} );
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if ( map.size === 0 ) {
|
|
46
|
+
throw new Error( 'Empty response' );
|
|
47
|
+
}
|
|
48
|
+
return map;
|
|
49
|
+
} catch ( error ) {
|
|
50
|
+
logger.error( `Models pricing: Data parsing failure "${error.message}".` );
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const fallbackTable = parseData( modelsPricingSnapshot );
|
|
56
|
+
|
|
57
|
+
const fetchData = async () => {
|
|
58
|
+
try {
|
|
59
|
+
const res = await fetch( costTableUrl, { dispatcher } );
|
|
60
|
+
if ( res.ok ) {
|
|
61
|
+
return await res.json();
|
|
62
|
+
} else {
|
|
63
|
+
logger.error( `Models pricing: Data fetch HTTP error ${res.status}.` );
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
} catch ( error ) {
|
|
67
|
+
logger.error( `Models pricing: Data fetch failure "${error.code ?? error.name}".` );
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const fetchModelsPricing = async () => {
|
|
73
|
+
if ( cache.content && cache.expiresAt > Date.now() ) {
|
|
74
|
+
return { models: cache.content, freshness: Freshness.CACHED };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if ( state.ignoreLiveRequestsUntil < Date.now() ) {
|
|
78
|
+
const table = await fetchData();
|
|
79
|
+
const models = table ? parseData( table ) : null;
|
|
80
|
+
|
|
81
|
+
if ( models ) {
|
|
82
|
+
cache.content = models;
|
|
83
|
+
cache.expiresAt = Date.now() + cacheTTL;
|
|
84
|
+
return { models, freshness: Freshness.LIVE };
|
|
85
|
+
} else {
|
|
86
|
+
state.ignoreLiveRequestsUntil = Date.now() + cooldownTTL;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if ( cache.content ) {
|
|
91
|
+
logger.warn( 'Models pricing: using stale cache.' );
|
|
92
|
+
return { models: cache.content, freshness: Freshness.STALE };
|
|
93
|
+
}
|
|
94
|
+
logger.warn( 'Models pricing: using built-in fallback.' );
|
|
95
|
+
return { models: fallbackTable, freshness: Freshness.SNAPSHOT };
|
|
96
|
+
};
|