@primero.ai/temporal-graph-tools 1.3.0 → 1.4.1
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/examples/mastra-ai-workflow/activities/classify-outage-with-ai.d.ts.map +1 -1
- package/dist/examples/mastra-ai-workflow/activities/classify-outage-with-ai.js +19 -20
- package/dist/examples/mastra-ai-workflow/activities/draft-response-with-ai.d.ts.map +1 -1
- package/dist/examples/mastra-ai-workflow/activities/draft-response-with-ai.js +10 -13
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/mastra/ai-model.d.ts +16 -0
- package/dist/src/mastra/ai-model.d.ts.map +1 -0
- package/dist/src/mastra/ai-model.js +87 -0
- package/package.json +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify-outage-with-ai.d.ts","sourceRoot":"","sources":["../../../../examples/mastra-ai-workflow/activities/classify-outage-with-ai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"classify-outage-with-ai.d.ts","sourceRoot":"","sources":["../../../../examples/mastra-ai-workflow/activities/classify-outage-with-ai.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,SAAS,GAAG,SAAS,CAAA;AACjE,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;AAErD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,YAAY,CAAA;IACpB,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAiED,eAAO,MAAM,oBAAoB,2FA0DhC,CAAA"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
import { openai } from '@ai-sdk/openai';
|
|
3
1
|
import { z } from 'zod';
|
|
4
|
-
import { wrapActivityWithMastraAgent } from '@primero.ai/temporal-graph-tools';
|
|
2
|
+
import { resolveAiSelection, selectAiModel, wrapActivityWithMastraAgent, } from '@primero.ai/temporal-graph-tools';
|
|
5
3
|
function inferIntent(message) {
|
|
6
4
|
const normalized = message.toLowerCase();
|
|
7
5
|
if (normalized.includes('invoice') ||
|
|
@@ -40,26 +38,27 @@ function inferRootCause(message) {
|
|
|
40
38
|
}
|
|
41
39
|
return 'unknown';
|
|
42
40
|
}
|
|
43
|
-
const modelId = (_a = process.env.MASTRA_AI_MODEL) !== null && _a !== void 0 ? _a : 'gpt-4o-mini';
|
|
44
41
|
const classificationOutputSchema = z.object({
|
|
45
42
|
intent: z.enum(['connectivity', 'billing', 'account']),
|
|
46
43
|
urgency: z.enum(['low', 'medium', 'high']),
|
|
47
44
|
summary: z.string(),
|
|
48
45
|
recommendedFix: z.string(),
|
|
49
46
|
});
|
|
50
|
-
const classificationAgentInput = {
|
|
51
|
-
id: 'mastra-outage-classifier',
|
|
52
|
-
name: 'Mastra Outage Classifier',
|
|
53
|
-
instructions: [
|
|
54
|
-
'You classify support tickets and propose precise remediation.',
|
|
55
|
-
'If the outage seems local-network and no provider outage is reported, recommend restarting the router.',
|
|
56
|
-
'Return concise and operational output.',
|
|
57
|
-
].join(' '),
|
|
58
|
-
model: openai(modelId),
|
|
59
|
-
};
|
|
60
47
|
export const classifyOutageWithAi = wrapActivityWithMastraAgent(async ({ input: ticket, agent }) => {
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
const aiSelection = resolveAiSelection({
|
|
49
|
+
defaultModel: 'gpt-4o-mini',
|
|
50
|
+
defaultProvider: 'openai',
|
|
51
|
+
});
|
|
52
|
+
const classificationAgentInput = {
|
|
53
|
+
id: 'mastra-outage-classifier',
|
|
54
|
+
name: 'Mastra Outage Classifier',
|
|
55
|
+
instructions: [
|
|
56
|
+
'You classify support tickets and propose precise remediation.',
|
|
57
|
+
'If the outage seems local-network and no provider outage is reported, recommend restarting the router.',
|
|
58
|
+
'Return concise and operational output.',
|
|
59
|
+
].join(' '),
|
|
60
|
+
model: selectAiModel(aiSelection),
|
|
61
|
+
};
|
|
63
62
|
const fallbackIntent = inferIntent(ticket.outageDescription);
|
|
64
63
|
const fallbackUrgency = inferUrgency(ticket.outageDescription);
|
|
65
64
|
const fallbackSummary = ticket.outageDescription.slice(0, 180);
|
|
@@ -79,8 +78,8 @@ export const classifyOutageWithAi = wrapActivityWithMastraAgent(async ({ input:
|
|
|
79
78
|
schema: classificationOutputSchema,
|
|
80
79
|
});
|
|
81
80
|
return {
|
|
82
|
-
provider,
|
|
83
|
-
model:
|
|
81
|
+
provider: aiSelection.provider,
|
|
82
|
+
model: aiSelection.model,
|
|
84
83
|
intent: parsed.intent,
|
|
85
84
|
urgency: parsed.urgency,
|
|
86
85
|
summary: parsed.summary,
|
|
@@ -91,8 +90,8 @@ export const classifyOutageWithAi = wrapActivityWithMastraAgent(async ({ input:
|
|
|
91
90
|
console.warn('[mastra-ai] classifyOutageWithAi fallback:', error);
|
|
92
91
|
}
|
|
93
92
|
return {
|
|
94
|
-
provider,
|
|
95
|
-
model:
|
|
93
|
+
provider: aiSelection.provider,
|
|
94
|
+
model: aiSelection.model,
|
|
96
95
|
intent: fallbackIntent,
|
|
97
96
|
urgency: fallbackUrgency,
|
|
98
97
|
summary: fallbackSummary,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-response-with-ai.d.ts","sourceRoot":"","sources":["../../../../examples/mastra-ai-workflow/activities/draft-response-with-ai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"draft-response-with-ai.d.ts","sourceRoot":"","sources":["../../../../examples/mastra-ai-workflow/activities/draft-response-with-ai.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAEtE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oBAAoB,EAAE,gBAAgB,CAAA;IACtC,uBAAuB,EAAE,mBAAmB,CAAA;CAC7C,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAOD,eAAO,MAAM,mBAAmB,4FAiD/B,CAAA"}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
import { openai } from '@ai-sdk/openai';
|
|
3
1
|
import { z } from 'zod';
|
|
4
|
-
import { wrapActivityWithMastraAgent } from '@primero.ai/temporal-graph-tools';
|
|
5
|
-
const modelId = (_a = process.env.MASTRA_AI_MODEL) !== null && _a !== void 0 ? _a : 'gpt-4o-mini';
|
|
2
|
+
import { selectAiModel, wrapActivityWithMastraAgent } from '@primero.ai/temporal-graph-tools';
|
|
6
3
|
const responseOutputSchema = z.object({
|
|
7
4
|
subject: z.string(),
|
|
8
5
|
body: z.string(),
|
|
9
6
|
});
|
|
10
|
-
const responseAgentInput = {
|
|
11
|
-
id: 'mastra-response-writer',
|
|
12
|
-
name: 'Mastra Response Writer',
|
|
13
|
-
instructions: [
|
|
14
|
-
'You write short, professional customer responses for internet incidents.',
|
|
15
|
-
'If evidence indicates local-network issue without provider outage, explicitly instruct router restart.',
|
|
16
|
-
].join(' '),
|
|
17
|
-
model: openai(modelId),
|
|
18
|
-
};
|
|
19
7
|
export const draftResponseWithAi = wrapActivityWithMastraAgent(async ({ input: analysis, agent }) => {
|
|
8
|
+
const responseAgentInput = {
|
|
9
|
+
id: 'mastra-response-writer',
|
|
10
|
+
name: 'Mastra Response Writer',
|
|
11
|
+
instructions: [
|
|
12
|
+
'You write short, professional customer responses for internet incidents.',
|
|
13
|
+
'If evidence indicates local-network issue without provider outage, explicitly instruct router restart.',
|
|
14
|
+
].join(' '),
|
|
15
|
+
model: selectAiModel({ defaultModel: 'gpt-4o-mini' }),
|
|
16
|
+
};
|
|
20
17
|
const { classifyOutageWithAi: ai, enrichOutageDescription: enriched } = analysis;
|
|
21
18
|
const fallbackSubject = `[${ai.intent.toUpperCase()}][${ai.urgency}] Internet Incident`;
|
|
22
19
|
const fallbackBody = [
|
package/dist/src/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './workflow-bundler.js';
|
|
|
4
4
|
export { collectWorkflowBuildResults } from './workflow/collection.js';
|
|
5
5
|
export * from './bundler.js';
|
|
6
6
|
export * from './mastra/agent-wrapper.js';
|
|
7
|
+
export * from './mastra/ai-model.js';
|
|
7
8
|
export * from './mastra/create-activity-with-mastra.js';
|
|
8
9
|
export * from './mastra/with-mastra-agent.js';
|
|
9
10
|
export * from './mastra/workflow-compiler.js';
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC9E,cAAc,uBAAuB,CAAA;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AACtE,cAAc,cAAc,CAAA;AAC5B,cAAc,2BAA2B,CAAA;AACzC,cAAc,yCAAyC,CAAA;AACvD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC9E,cAAc,uBAAuB,CAAA;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AACtE,cAAc,cAAc,CAAA;AAC5B,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AACpC,cAAc,yCAAyC,CAAA;AACvD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from './workflow-bundler.js';
|
|
|
4
4
|
export { collectWorkflowBuildResults } from './workflow/collection.js';
|
|
5
5
|
export * from './bundler.js';
|
|
6
6
|
export * from './mastra/agent-wrapper.js';
|
|
7
|
+
export * from './mastra/ai-model.js';
|
|
7
8
|
export * from './mastra/create-activity-with-mastra.js';
|
|
8
9
|
export * from './mastra/with-mastra-agent.js';
|
|
9
10
|
export * from './mastra/workflow-compiler.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { openai } from '@ai-sdk/openai';
|
|
2
|
+
export type SupportedAiProvider = 'anthropic' | 'azure' | 'deepseek' | 'google' | 'openai' | 'xai';
|
|
3
|
+
export type AiModelSelectionOptions = {
|
|
4
|
+
provider?: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
defaultProvider?: SupportedAiProvider;
|
|
7
|
+
defaultModel?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolveAiProvider(options?: Pick<AiModelSelectionOptions, 'provider' | 'defaultProvider'>): SupportedAiProvider;
|
|
10
|
+
export declare function resolveAiModel(options?: Pick<AiModelSelectionOptions, 'model' | 'defaultModel'>): string;
|
|
11
|
+
export declare function resolveAiSelection(options?: AiModelSelectionOptions): {
|
|
12
|
+
provider: SupportedAiProvider;
|
|
13
|
+
model: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function selectAiModel(options?: AiModelSelectionOptions): ReturnType<typeof openai>;
|
|
16
|
+
//# sourceMappingURL=ai-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-model.d.ts","sourceRoot":"","sources":["../../../src/mastra/ai-model.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGvC,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAA;AAElG,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,eAAe,CAAC,EAAE,mBAAmB,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAqCD,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,IAAI,CAAC,uBAAuB,EAAE,UAAU,GAAG,iBAAiB,CAAM,GAC1E,mBAAmB,CAuBrB;AAED,wBAAgB,cAAc,CAC5B,OAAO,GAAE,IAAI,CAAC,uBAAuB,EAAE,OAAO,GAAG,cAAc,CAAM,GACpE,MAAM,CAeR;AAED,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,uBAA4B,GAAG;IACzE,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,KAAK,EAAE,MAAM,CAAA;CACd,CAKA;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,uBAA4B,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CA4B9F"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
2
|
+
import { azure } from '@ai-sdk/azure';
|
|
3
|
+
import { deepseek } from '@ai-sdk/deepseek';
|
|
4
|
+
import { google } from '@ai-sdk/google';
|
|
5
|
+
import { openai } from '@ai-sdk/openai';
|
|
6
|
+
import { xai } from '@ai-sdk/xai';
|
|
7
|
+
const DEFAULT_PROVIDER = 'openai';
|
|
8
|
+
const PROVIDER_ALIASES = Object.freeze({
|
|
9
|
+
claude: 'anthropic',
|
|
10
|
+
gemini: 'google',
|
|
11
|
+
});
|
|
12
|
+
function normalizeString(value) {
|
|
13
|
+
if (typeof value !== 'string') {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const normalized = value.trim();
|
|
17
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
18
|
+
}
|
|
19
|
+
function readDagAiConfig() {
|
|
20
|
+
const raw = process.env.PRIMERO_DAG_AI_CONFIG;
|
|
21
|
+
if (!raw) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(raw);
|
|
26
|
+
return {
|
|
27
|
+
provider: typeof parsed.provider === 'string' ? parsed.provider : undefined,
|
|
28
|
+
model: typeof parsed.model === 'string' ? parsed.model : undefined,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function resolveAiProvider(options = {}) {
|
|
36
|
+
var _a, _b, _c, _d, _e;
|
|
37
|
+
const dagAiConfig = readDagAiConfig();
|
|
38
|
+
const candidate = (_d = (_c = (_b = (_a = normalizeString(options.provider)) !== null && _a !== void 0 ? _a : normalizeString(dagAiConfig.provider)) !== null && _b !== void 0 ? _b : normalizeString(process.env.AI_PROVIDER)) !== null && _c !== void 0 ? _c : options.defaultProvider) !== null && _d !== void 0 ? _d : DEFAULT_PROVIDER;
|
|
39
|
+
const lowered = candidate.toLowerCase();
|
|
40
|
+
const resolved = (_e = PROVIDER_ALIASES[lowered]) !== null && _e !== void 0 ? _e : lowered;
|
|
41
|
+
if (resolved === 'openai' ||
|
|
42
|
+
resolved === 'anthropic' ||
|
|
43
|
+
resolved === 'google' ||
|
|
44
|
+
resolved === 'xai' ||
|
|
45
|
+
resolved === 'deepseek' ||
|
|
46
|
+
resolved === 'azure') {
|
|
47
|
+
return resolved;
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Unsupported AI provider '${candidate}'.`);
|
|
50
|
+
}
|
|
51
|
+
export function resolveAiModel(options = {}) {
|
|
52
|
+
var _a, _b, _c;
|
|
53
|
+
const dagAiConfig = readDagAiConfig();
|
|
54
|
+
const model = (_c = (_b = (_a = normalizeString(options.model)) !== null && _a !== void 0 ? _a : normalizeString(dagAiConfig.model)) !== null && _b !== void 0 ? _b : normalizeString(process.env.AI_MODEL)) !== null && _c !== void 0 ? _c : normalizeString(options.defaultModel);
|
|
55
|
+
if (!model) {
|
|
56
|
+
throw new Error('No AI model configured. Pass a model option, set PRIMERO_DAG_AI_CONFIG, or set AI_MODEL in the environment.');
|
|
57
|
+
}
|
|
58
|
+
return model;
|
|
59
|
+
}
|
|
60
|
+
export function resolveAiSelection(options = {}) {
|
|
61
|
+
return {
|
|
62
|
+
provider: resolveAiProvider(options),
|
|
63
|
+
model: resolveAiModel(options),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function selectAiModel(options = {}) {
|
|
67
|
+
const { provider, model } = resolveAiSelection(options);
|
|
68
|
+
if (provider === 'openai') {
|
|
69
|
+
return openai(model);
|
|
70
|
+
}
|
|
71
|
+
if (provider === 'anthropic') {
|
|
72
|
+
return anthropic(model);
|
|
73
|
+
}
|
|
74
|
+
if (provider === 'google') {
|
|
75
|
+
return google(model);
|
|
76
|
+
}
|
|
77
|
+
if (provider === 'xai') {
|
|
78
|
+
return xai(model);
|
|
79
|
+
}
|
|
80
|
+
if (provider === 'deepseek') {
|
|
81
|
+
return deepseek(model);
|
|
82
|
+
}
|
|
83
|
+
if (provider === 'azure') {
|
|
84
|
+
return azure(model);
|
|
85
|
+
}
|
|
86
|
+
throw new Error('Unsupported AI provider.');
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primero.ai/temporal-graph-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Utilities for working with DAG workflows.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/primero-ai/temporal-graph-tools#readme",
|
|
@@ -73,7 +73,12 @@
|
|
|
73
73
|
"clean": "rm -rf node_modules dist"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
+
"@ai-sdk/anthropic": "^3.0.45",
|
|
77
|
+
"@ai-sdk/azure": "^3.0.31",
|
|
78
|
+
"@ai-sdk/deepseek": "^2.0.20",
|
|
79
|
+
"@ai-sdk/google": "^3.0.30",
|
|
76
80
|
"@ai-sdk/openai": "^3.0.30",
|
|
81
|
+
"@ai-sdk/xai": "^3.0.57",
|
|
77
82
|
"@mastra/core": "^1.4.0",
|
|
78
83
|
"@temporalio/activity": "^1.15.0",
|
|
79
84
|
"@temporalio/client": "1.15.0",
|