Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieKolb committed Feb 4, 2025
1 parent 5d70ed9 commit 164a3b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/events/relays/telemetry.event-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ export class TelemetryEventRelay extends EventRelay {
sharing_role: userRole,
credential_type: null,
is_managed: false,
...TelemetryHelpers.makeAIMetrics(workflow.nodes, this.nodeTypes),
...TelemetryHelpers.resolveAIMetrics(workflow.nodes, this.nodeTypes),
};

if (!manualExecEventProperties.node_graph_string) {
Expand Down
29 changes: 15 additions & 14 deletions packages/workflow/src/TelemetryHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export type FromAICount = {
fromAIExpressionCount: number;
};

export function makeAIMetrics(nodes: INode[], nodeTypes: INodeTypes): FromAICount | {} {
export function resolveAIMetrics(nodes: INode[], nodeTypes: INodeTypes): FromAICount | {} {
const resolvedNodes = nodes
.map((x) => [x, nodeTypes.getByNameAndVersion(x.type, x.typeVersion)] as const)
.filter((x) => !!x[1]?.description);
Expand All @@ -549,25 +549,31 @@ export function makeAIMetrics(nodes: INode[], nodeTypes: INodeTypes): FromAICoun
let fromAIOverrideCount = 0;
let fromAIExpressionCount = 0;

const tools = resolvedNodes.filter((x) =>
x[1].description.codex?.subcategories?.AI?.includes('Tools'),
const tools = resolvedNodes.filter((node) =>
node[1].description.codex?.subcategories?.AI?.includes('Tools'),
);

for (const [node, _] of tools) {
// FlatMap to support values in resourceLocators
const vals = Object.values(node.parameters).flatMap((x) => {
if (x && typeof x === 'object' && 'value' in x) x = x.value;
return typeof x === 'string' ? x : [];
const values = Object.values(node.parameters).flatMap((param) => {
if (param && typeof param === 'object' && 'value' in param) param = param.value;
return typeof param === 'string' ? param : [];
});

// Note that we don't match the i in `fromAI` to support lower case i (though we miss fromai)
const overrides = vals.reduce(
(acc, x) => acc + Number(x.startsWith(`={{ ${FROM_AI_AUTO_GENERATED_MARKER} $fromA`)),
const overrides = values.reduce(
(acc, value) => acc + Number(value.startsWith(`={{ ${FROM_AI_AUTO_GENERATED_MARKER} $fromA`)),
0,
);

fromAIOverrideCount += overrides;
// check for = to avoid scanning lengthy text fields
// this will re-count overrides
fromAIExpressionCount +=
vals.reduce((acc, x) => acc + Number(x[0] === '=' && x.includes('$fromA', 2)), 0) - overrides;
values.reduce(
(acc, value) => acc + Number(value[0] === '=' && value.includes('$fromA', 2)),
0,
) - overrides;
}

return {
Expand All @@ -577,8 +583,3 @@ export function makeAIMetrics(nodes: INode[], nodeTypes: INodeTypes): FromAICoun
fromAIExpressionCount,
};
}

export function isTool(nodeTypes: INodeTypes, node: INode): boolean {
const x = nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
return !!x.description.codex?.subcategories?.AI?.includes('Tool');
}
8 changes: 4 additions & 4 deletions packages/workflow/test/TelemetryHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
generateNodesGraph,
getDomainBase,
getDomainPath,
makeAIMetrics,
resolveAIMetrics,
userInInstanceRanOutOfFreeAiCredits,
} from '@/TelemetryHelpers';
import { randomInt } from '@/utils';
Expand Down Expand Up @@ -1591,7 +1591,7 @@ describe('makeAIMetrics', () => {
}),
});

const result = makeAIMetrics(nodes, nodeTypes);
const result = resolveAIMetrics(nodes, nodeTypes);
expect(result).toMatchObject({
aiNodeCount: 3,
aiToolCount: 3,
Expand All @@ -1616,7 +1616,7 @@ describe('makeAIMetrics', () => {
}),
});

const result = makeAIMetrics(nodes, nodeTypes);
const result = resolveAIMetrics(nodes, nodeTypes);
expect(result).toMatchObject({});
});

Expand All @@ -1640,7 +1640,7 @@ describe('makeAIMetrics', () => {
}),
});

const result = makeAIMetrics(nodes, nodeTypes);
const result = resolveAIMetrics(nodes, nodeTypes);
expect(result).toMatchObject({
aiNodeCount: 1,
aiToolCount: 0,
Expand Down

0 comments on commit 164a3b1

Please sign in to comment.