@agentuity/runtime 1.0.23 → 1.0.25
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/dev-patches/aisdk.d.ts +17 -0
- package/dist/dev-patches/aisdk.d.ts.map +1 -0
- package/dist/dev-patches/aisdk.js +154 -0
- package/dist/dev-patches/aisdk.js.map +1 -0
- package/dist/dev-patches/gateway.d.ts +16 -0
- package/dist/dev-patches/gateway.d.ts.map +1 -0
- package/dist/dev-patches/gateway.js +55 -0
- package/dist/dev-patches/gateway.js.map +1 -0
- package/dist/dev-patches/index.d.ts +21 -0
- package/dist/dev-patches/index.d.ts.map +1 -0
- package/dist/dev-patches/index.js +33 -0
- package/dist/dev-patches/index.js.map +1 -0
- package/dist/dev-patches/otel-llm.d.ts +12 -0
- package/dist/dev-patches/otel-llm.d.ts.map +1 -0
- package/dist/dev-patches/otel-llm.js +345 -0
- package/dist/dev-patches/otel-llm.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/services/local/_db.d.ts.map +1 -1
- package/dist/services/local/_db.js +78 -1
- package/dist/services/local/_db.js.map +1 -1
- package/dist/services/local/email.d.ts +2 -0
- package/dist/services/local/email.d.ts.map +1 -1
- package/dist/services/local/email.js +6 -0
- package/dist/services/local/email.js.map +1 -1
- package/dist/services/local/task.d.ts +26 -1
- package/dist/services/local/task.d.ts.map +1 -1
- package/dist/services/local/task.js +304 -4
- package/dist/services/local/task.js.map +1 -1
- package/package.json +7 -7
- package/src/dev-patches/aisdk.ts +172 -0
- package/src/dev-patches/gateway.ts +70 -0
- package/src/dev-patches/index.ts +37 -0
- package/src/dev-patches/otel-llm.ts +408 -0
- package/src/index.ts +3 -0
- package/src/services/local/_db.ts +98 -5
- package/src/services/local/email.ts +9 -4
- package/src/services/local/task.ts +448 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime AI SDK patches for dev mode.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the build-time patches from cli/src/cmd/build/patch/aisdk.ts.
|
|
5
|
+
* Monkey-patches Vercel AI SDK functions to:
|
|
6
|
+
* 1. Enable experimental telemetry on all AI function calls
|
|
7
|
+
* 2. Route AI SDK provider factory functions through the AI Gateway
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Patch AI SDK core functions (generateText, streamText, etc.) with telemetry injection.
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyAISDKCorePatches(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Patch AI SDK provider factory functions to route through the AI Gateway.
|
|
15
|
+
*/
|
|
16
|
+
export declare function applyAISDKProviderPatches(): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=aisdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aisdk.d.ts","sourceRoot":"","sources":["../../src/dev-patches/aisdk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAmIH;;GAEG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAa3D;AAED;;GAEG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CAY/D"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime AI SDK patches for dev mode.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the build-time patches from cli/src/cmd/build/patch/aisdk.ts.
|
|
5
|
+
* Monkey-patches Vercel AI SDK functions to:
|
|
6
|
+
* 1. Enable experimental telemetry on all AI function calls
|
|
7
|
+
* 2. Route AI SDK provider factory functions through the AI Gateway
|
|
8
|
+
*/
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
|
+
function warnMissingKey(envKey) {
|
|
11
|
+
const isDev = process.env.AGENTUITY_ENVIRONMENT === 'development' || process.env.NODE_ENV !== 'production';
|
|
12
|
+
if (isDev) {
|
|
13
|
+
console.error('[ERROR] No credentials found for this AI provider. To fix this, either:');
|
|
14
|
+
console.error(' 1. Login to Agentuity Cloud (agentuity auth login) to use the AI Gateway (recommended)');
|
|
15
|
+
console.error(` 2. Set ${envKey} in your .env file to use the provider directly`);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.error(`[ERROR] The environment variable ${envKey} is required. Either:`);
|
|
19
|
+
console.error(' 1. Use Agentuity Cloud AI Gateway by ensuring AGENTUITY_SDK_KEY is configured');
|
|
20
|
+
console.error(` 2. Set ${envKey} using "agentuity env set ${envKey}" and redeploy`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Wrap an AI SDK function to inject experimental_telemetry: { isEnabled: true }.
|
|
25
|
+
*/
|
|
26
|
+
function wrapWithTelemetry(originalFn) {
|
|
27
|
+
return function (...args) {
|
|
28
|
+
const opts = { ...(args[0] ?? {}) };
|
|
29
|
+
opts.experimental_telemetry = { isEnabled: true };
|
|
30
|
+
args[0] = opts;
|
|
31
|
+
return originalFn.apply(this, args);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wrap a provider factory function (e.g., createOpenAI) to inject gateway config.
|
|
36
|
+
*/
|
|
37
|
+
function wrapProviderFactory(originalFn, envKey, provider) {
|
|
38
|
+
return function (...args) {
|
|
39
|
+
const currentKey = process.env[envKey];
|
|
40
|
+
const sdkKey = process.env.AGENTUITY_SDK_KEY;
|
|
41
|
+
// If user provided their own key (and it's not the SDK key), leave it alone
|
|
42
|
+
if (currentKey && currentKey !== sdkKey) {
|
|
43
|
+
if (!sdkKey) {
|
|
44
|
+
console.log(`User provided ${provider} api key set. Use the Agentuity AI Gateway more features.`);
|
|
45
|
+
}
|
|
46
|
+
return originalFn.apply(this, args);
|
|
47
|
+
}
|
|
48
|
+
// Route through gateway
|
|
49
|
+
const transportUrl = process.env.AGENTUITY_TRANSPORT_URL;
|
|
50
|
+
if (transportUrl && sdkKey) {
|
|
51
|
+
const opts = { ...(args[0] ?? {}) };
|
|
52
|
+
if (!opts.baseURL) {
|
|
53
|
+
opts.apiKey = sdkKey;
|
|
54
|
+
opts.baseURL = `${transportUrl}/gateway/${provider}`;
|
|
55
|
+
args[0] = opts;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (!currentKey) {
|
|
59
|
+
warnMissingKey(envKey);
|
|
60
|
+
}
|
|
61
|
+
return originalFn.apply(this, args);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** AI SDK core functions to wrap with telemetry injection */
|
|
65
|
+
const AI_CORE_FUNCTIONS = [
|
|
66
|
+
'generateText',
|
|
67
|
+
'streamText',
|
|
68
|
+
'generateObject',
|
|
69
|
+
'streamObject',
|
|
70
|
+
'embed',
|
|
71
|
+
'embedMany',
|
|
72
|
+
];
|
|
73
|
+
/** AI SDK provider packages and their factory functions */
|
|
74
|
+
const AI_PROVIDER_CONFIGS = [
|
|
75
|
+
{
|
|
76
|
+
module: '@ai-sdk/openai',
|
|
77
|
+
factory: 'createOpenAI',
|
|
78
|
+
envKey: 'OPENAI_API_KEY',
|
|
79
|
+
provider: 'openai',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
module: '@ai-sdk/anthropic',
|
|
83
|
+
factory: 'createAnthropic',
|
|
84
|
+
envKey: 'ANTHROPIC_API_KEY',
|
|
85
|
+
provider: 'anthropic',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
module: '@ai-sdk/cohere',
|
|
89
|
+
factory: 'createCohere',
|
|
90
|
+
envKey: 'COHERE_API_KEY',
|
|
91
|
+
provider: 'cohere',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
module: '@ai-sdk/deepseek',
|
|
95
|
+
factory: 'createDeepSeek',
|
|
96
|
+
envKey: 'DEEPSEEK_API_KEY',
|
|
97
|
+
provider: 'deepseek',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
module: '@ai-sdk/google',
|
|
101
|
+
factory: 'createGoogleGenerativeAI',
|
|
102
|
+
envKey: 'GOOGLE_GENERATIVE_AI_API_KEY',
|
|
103
|
+
provider: 'google-ai-studio',
|
|
104
|
+
},
|
|
105
|
+
{ module: '@ai-sdk/xai', factory: 'createXai', envKey: 'XAI_API_KEY', provider: 'grok' },
|
|
106
|
+
{ module: '@ai-sdk/groq', factory: 'createGroq', envKey: 'GROQ_API_KEY', provider: 'groq' },
|
|
107
|
+
{
|
|
108
|
+
module: '@ai-sdk/mistral',
|
|
109
|
+
factory: 'createMistral',
|
|
110
|
+
envKey: 'MISTRAL_API_KEY',
|
|
111
|
+
provider: 'mistral',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
module: '@ai-sdk/perplexity',
|
|
115
|
+
factory: 'createPerplexity',
|
|
116
|
+
envKey: 'PERPLEXITY_API_KEY',
|
|
117
|
+
provider: 'perplexity-ai',
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
/**
|
|
121
|
+
* Patch AI SDK core functions (generateText, streamText, etc.) with telemetry injection.
|
|
122
|
+
*/
|
|
123
|
+
export async function applyAISDKCorePatches() {
|
|
124
|
+
try {
|
|
125
|
+
const aiModule = await import('ai');
|
|
126
|
+
for (const fnName of AI_CORE_FUNCTIONS) {
|
|
127
|
+
const original = aiModule[fnName];
|
|
128
|
+
if (typeof original === 'function') {
|
|
129
|
+
aiModule[fnName] = wrapWithTelemetry(original);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// 'ai' package not installed — skip
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Patch AI SDK provider factory functions to route through the AI Gateway.
|
|
139
|
+
*/
|
|
140
|
+
export async function applyAISDKProviderPatches() {
|
|
141
|
+
for (const config of AI_PROVIDER_CONFIGS) {
|
|
142
|
+
try {
|
|
143
|
+
const mod = await import(config.module);
|
|
144
|
+
const original = mod[config.factory];
|
|
145
|
+
if (typeof original === 'function') {
|
|
146
|
+
mod[config.factory] = wrapProviderFactory(original, config.envKey, config.provider);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// Provider package not installed — skip
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=aisdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aisdk.js","sourceRoot":"","sources":["../../src/dev-patches/aisdk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uDAAuD;AAEvD,SAAS,cAAc,CAAC,MAAc;IACrC,MAAM,KAAK,GACV,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAC9F,IAAI,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,yEAAyE,CAAC,CAAC;QACzF,OAAO,CAAC,KAAK,CACZ,0FAA0F,CAC1F,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,YAAY,MAAM,iDAAiD,CAAC,CAAC;IACpF,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,KAAK,CAAC,oCAAoC,MAAM,uBAAuB,CAAC,CAAC;QACjF,OAAO,CAAC,KAAK,CACZ,iFAAiF,CACjF,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,YAAY,MAAM,6BAA6B,MAAM,gBAAgB,CAAC,CAAC;IACtF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB,CAAC,UAAmC;IAC7D,OAAO,UAAqB,GAAG,IAAW;QACzC,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QACpC,IAAI,CAAC,sBAAsB,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QACl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AEX;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB;IAC1C,IAAI,CAAC;QACJ,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;QAEpC,KAAK,MAAM,MAAM,IAAI,iBAAiB,EAAE,CAAC;YACxC,MAAM,QAAQ,GAAI,QAAgB,CAAC,MAAM,CAAC,CAAC;YAC3C,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;gBACnC,QAAgB,CAAC,MAAM,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YACzD,CAAC;QACF,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,oCAAoC;IACrC,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB;IAC9C,KAAK,MAAM,MAAM,IAAI,mBAAmB,EAAE,CAAC;QAC1C,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACxC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;gBACpC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YACrF,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,wCAAwC;QACzC,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime LLM Gateway patches for dev mode.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the build-time patches from cli/src/cmd/build/patch/llm.ts.
|
|
5
|
+
* Sets environment variables to route LLM SDK calls through the Agentuity AI Gateway
|
|
6
|
+
* when the user hasn't provided their own API keys.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Set environment variables to route LLM calls through the AI Gateway.
|
|
10
|
+
*
|
|
11
|
+
* For each provider, if the user hasn't set their own API key (or it equals
|
|
12
|
+
* the SDK key), we redirect to the gateway. This matches the behavior of
|
|
13
|
+
* the build-time patches in patch/llm.ts.
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyGatewayPatches(): void;
|
|
16
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/dev-patches/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgCH;;;;;;GAMG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAwB1C"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime LLM Gateway patches for dev mode.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the build-time patches from cli/src/cmd/build/patch/llm.ts.
|
|
5
|
+
* Sets environment variables to route LLM SDK calls through the Agentuity AI Gateway
|
|
6
|
+
* when the user hasn't provided their own API keys.
|
|
7
|
+
*/
|
|
8
|
+
const GATEWAY_CONFIGS = [
|
|
9
|
+
{ apiKeyEnv: 'ANTHROPIC_API_KEY', baseUrlEnv: 'ANTHROPIC_BASE_URL', provider: 'anthropic' },
|
|
10
|
+
{ apiKeyEnv: 'GROQ_API_KEY', baseUrlEnv: 'GROQ_BASE_URL', provider: 'groq' },
|
|
11
|
+
{ apiKeyEnv: 'OPENAI_API_KEY', baseUrlEnv: 'OPENAI_BASE_URL', provider: 'openai' },
|
|
12
|
+
];
|
|
13
|
+
function warnMissingKey(envKey) {
|
|
14
|
+
const isDev = process.env.AGENTUITY_ENVIRONMENT === 'development' || process.env.NODE_ENV !== 'production';
|
|
15
|
+
if (isDev) {
|
|
16
|
+
console.error('[ERROR] No credentials found for this AI provider. To fix this, either:');
|
|
17
|
+
console.error(' 1. Login to Agentuity Cloud (agentuity auth login) to use the AI Gateway (recommended)');
|
|
18
|
+
console.error(` 2. Set ${envKey} in your .env file to use the provider directly`);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.error(`[ERROR] The environment variable ${envKey} is required. Either:`);
|
|
22
|
+
console.error(' 1. Use Agentuity Cloud AI Gateway by ensuring AGENTUITY_SDK_KEY is configured');
|
|
23
|
+
console.error(` 2. Set ${envKey} using "agentuity env set ${envKey}" and redeploy`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Set environment variables to route LLM calls through the AI Gateway.
|
|
28
|
+
*
|
|
29
|
+
* For each provider, if the user hasn't set their own API key (or it equals
|
|
30
|
+
* the SDK key), we redirect to the gateway. This matches the behavior of
|
|
31
|
+
* the build-time patches in patch/llm.ts.
|
|
32
|
+
*/
|
|
33
|
+
export function applyGatewayPatches() {
|
|
34
|
+
const sdkKey = process.env.AGENTUITY_SDK_KEY;
|
|
35
|
+
const gatewayUrl = process.env.AGENTUITY_AIGATEWAY_URL ||
|
|
36
|
+
process.env.AGENTUITY_TRANSPORT_URL ||
|
|
37
|
+
(sdkKey ? 'https://agentuity.ai' : '');
|
|
38
|
+
for (const config of GATEWAY_CONFIGS) {
|
|
39
|
+
const currentKey = process.env[config.apiKeyEnv];
|
|
40
|
+
// If the user provided their own key (and it's not the SDK key), leave it alone
|
|
41
|
+
if (currentKey && currentKey !== sdkKey) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// Route through gateway if we have both URL and SDK key
|
|
45
|
+
if (gatewayUrl && sdkKey) {
|
|
46
|
+
process.env[config.apiKeyEnv] = sdkKey;
|
|
47
|
+
process.env[config.baseUrlEnv] = `${gatewayUrl}/gateway/${config.provider}`;
|
|
48
|
+
console.debug(`Enabled Agentuity AI Gateway for ${config.provider}`);
|
|
49
|
+
}
|
|
50
|
+
else if (!currentKey) {
|
|
51
|
+
warnMissingKey(config.apiKeyEnv);
|
|
52
|
+
}
|
|
53
|
+
}
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AAO,CAAC,GAAG,CAAC,uBAAuB;QACnC,CAAC,MAAM,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAExC,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAEjD,gFAAgF;QAChF,IAAI,UAAU,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;YACzC,SAAS;QACV,CAAC;QAED,wDAAwD;QACxD,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;YACvC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,GAAG,UAAU,YAAY,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC5E,OAAO,CAAC,KAAK,CAAC,oCAAoC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtE,CAAC;aAAM,IAAI,CAAC,UAAU,EAAE,CAAC;YACxB,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime dev patches — replaces build-time Bun.build patches for dev mode.
|
|
3
|
+
*
|
|
4
|
+
* When --experimental-no-bundle is used, the generated entry file (src/generated/app.ts)
|
|
5
|
+
* is run directly by Bun without bundling. These runtime patches apply the same
|
|
6
|
+
* monkey-patches that would normally be injected by the Bun.build plugin during bundling.
|
|
7
|
+
*
|
|
8
|
+
* Three categories of patches:
|
|
9
|
+
* 1. Gateway: Set env vars to route LLM calls through Agentuity AI Gateway
|
|
10
|
+
* 2. AI SDK: Wrap Vercel AI SDK functions with telemetry + gateway config
|
|
11
|
+
* 3. OTel LLM: Wrap LLM SDK .create() methods with OpenTelemetry spans
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Apply all runtime dev patches.
|
|
15
|
+
*
|
|
16
|
+
* Must be called:
|
|
17
|
+
* - AFTER bootstrapRuntimeEnv() (so env vars like AGENTUITY_SDK_KEY are loaded)
|
|
18
|
+
* - BEFORE any user code imports LLM SDKs
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyDevPatches(): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dev-patches/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;;;;GAMG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAYrD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime dev patches — replaces build-time Bun.build patches for dev mode.
|
|
3
|
+
*
|
|
4
|
+
* When --experimental-no-bundle is used, the generated entry file (src/generated/app.ts)
|
|
5
|
+
* is run directly by Bun without bundling. These runtime patches apply the same
|
|
6
|
+
* monkey-patches that would normally be injected by the Bun.build plugin during bundling.
|
|
7
|
+
*
|
|
8
|
+
* Three categories of patches:
|
|
9
|
+
* 1. Gateway: Set env vars to route LLM calls through Agentuity AI Gateway
|
|
10
|
+
* 2. AI SDK: Wrap Vercel AI SDK functions with telemetry + gateway config
|
|
11
|
+
* 3. OTel LLM: Wrap LLM SDK .create() methods with OpenTelemetry spans
|
|
12
|
+
*/
|
|
13
|
+
import { applyGatewayPatches } from './gateway';
|
|
14
|
+
import { applyAISDKCorePatches, applyAISDKProviderPatches } from './aisdk';
|
|
15
|
+
import { applyOtelLLMPatches } from './otel-llm';
|
|
16
|
+
/**
|
|
17
|
+
* Apply all runtime dev patches.
|
|
18
|
+
*
|
|
19
|
+
* Must be called:
|
|
20
|
+
* - AFTER bootstrapRuntimeEnv() (so env vars like AGENTUITY_SDK_KEY are loaded)
|
|
21
|
+
* - BEFORE any user code imports LLM SDKs
|
|
22
|
+
*/
|
|
23
|
+
export async function applyDevPatches() {
|
|
24
|
+
// 1. Set gateway env vars first (other patches may read them)
|
|
25
|
+
applyGatewayPatches();
|
|
26
|
+
// 2. Patch AI SDK core functions (telemetry injection)
|
|
27
|
+
await applyAISDKCorePatches();
|
|
28
|
+
// 3. Patch AI SDK provider factories (gateway routing)
|
|
29
|
+
await applyAISDKProviderPatches();
|
|
30
|
+
// 4. Patch LLM SDK prototypes with OTel spans
|
|
31
|
+
await applyOtelLLMPatches();
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dev-patches/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACpC,8DAA8D;IAC9D,mBAAmB,EAAE,CAAC;IAEtB,uDAAuD;IACvD,MAAM,qBAAqB,EAAE,CAAC;IAE9B,uDAAuD;IACvD,MAAM,yBAAyB,EAAE,CAAC;IAElC,8CAA8C;IAC9C,MAAM,mBAAmB,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime OpenTelemetry LLM instrumentation patches for dev mode.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the build-time patches from cli/src/cmd/build/patch/otel-llm.ts.
|
|
5
|
+
* Wraps LLM SDK methods (OpenAI, Anthropic, Groq) with OTel spans to capture
|
|
6
|
+
* model, tokens, latency, and streaming support.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Apply OTel instrumentation patches to LLM SDK prototype methods.
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyOtelLLMPatches(): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=otel-llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-llm.d.ts","sourceRoot":"","sources":["../../src/dev-patches/otel-llm.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA2XH;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAmBzD"}
|