n8n-nodes-octagon
Version:
Professional n8n node for Octagon AI Agents - Access 6 public-market specialists plus prediction markets, SEC filings, earnings transcripts, and stock data
337 lines • 14.4 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.OctagonAgents = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const packageInfo = __importStar(require("../../package.json"));
const PREDICTION_MARKETS_AGENT = 'octagon-prediction-markets-agent';
const KALSHI_URL_PATTERN = /https:\/\/kalshi\.com\/markets\/\S+/i;
function resolveModel(agent, mode) {
if (agent !== PREDICTION_MARKETS_AGENT) {
return agent;
}
if (mode === 'cache') {
return `${PREDICTION_MARKETS_AGENT}:cache`;
}
if (mode === 'refresh') {
return `${PREDICTION_MARKETS_AGENT}:refresh`;
}
return PREDICTION_MARKETS_AGENT;
}
function parseCachePayload(analysis) {
try {
const parsed = JSON.parse(analysis);
if (parsed === null || Array.isArray(parsed) || typeof parsed !== 'object') {
return undefined;
}
return parsed;
}
catch {
return undefined;
}
}
class OctagonAgents {
constructor() {
this.description = {
displayName: 'Octagon',
name: 'octagonAgents',
icon: 'file:octagon.svg',
group: ['input'],
version: 1,
subtitle: '={{$parameter["agent"]}}',
description: 'Financial AI agents',
defaults: {
name: 'Octagon',
},
usableAsTool: true,
inputs: ["main"],
outputs: ["main"],
credentials: [
{
name: 'octagonApi',
required: true,
},
],
properties: [
{
displayName: 'Agent',
name: 'agent',
type: 'options',
options: [
{
name: '01. Octagon Agent (Router)',
value: 'octagon-agent',
description: 'Intelligent agent router that analyzes queries and routes to specialized agents',
},
{
name: '02. SEC Agent',
value: 'octagon-sec-agent',
description: 'Public market intelligence - Analyzes SEC filings and public company disclosures',
},
{
name: '03. Transcripts Agent',
value: 'octagon-transcripts-agent',
description: 'Public market intelligence - Analyzes earnings call transcripts',
},
{
name: '04. Stock Data Agent',
value: 'octagon-stock-data-agent',
description: 'Public market intelligence - Provides real-time and historical stock market data',
},
{
name: '05. Holdings Agent',
value: 'octagon-holdings-agent',
description: 'Public market intelligence - Analyzes institutional holdings data',
},
{
name: '06. Financials Agent',
value: 'octagon-financials-agent',
description: 'Public market intelligence - Analyzes financial statements',
},
{
name: '07. Crypto Agent',
value: 'octagon-crypto-agent',
description: 'Public market intelligence - Analyzes cryptocurrency market data',
},
{
name: '08. Prediction Markets Agent',
value: PREDICTION_MARKETS_AGENT,
description: 'Deep research intelligence - Creates Kalshi prediction market reports',
},
{
name: '09. Deep Research Agent',
value: 'octagon-deep-research-agent',
description: 'Deep research intelligence - Conducts in-depth research',
},
],
default: 'octagon-agent',
description: 'Select the Octagon agent for your research task',
},
{
displayName: 'Prediction markets requests must include a Kalshi market URL in the query. Use Cache Search to inspect cached reports without refreshing, or Refresh Report to force a new report.',
name: 'predictionMarketsNotice',
type: 'notice',
default: '',
displayOptions: {
show: {
agent: [PREDICTION_MARKETS_AGENT],
},
},
},
{
displayName: 'Prediction Markets Mode',
name: 'predictionMarketsMode',
type: 'options',
displayOptions: {
show: {
agent: [PREDICTION_MARKETS_AGENT],
},
},
options: [
{
name: 'Default Report',
value: 'default',
description: 'Use cache first and refresh only on cache miss',
},
{
name: 'Cache Search',
value: 'cache',
description: 'Return cached report metadata without creating a new report',
},
{
name: 'Refresh Report',
value: 'refresh',
description: 'Always create a new report before returning content',
},
],
default: 'default',
description: 'Choose how the prediction markets agent should resolve report data',
},
{
displayName: 'Query',
name: 'query',
type: 'string',
typeOptions: {
rows: 3,
},
default: '',
placeholder: 'Ask any financial or market research question. Prediction markets queries must include a Kalshi market URL...',
description: 'Your research query or question. Prediction markets requests must include a Kalshi market URL.',
required: true,
},
{
displayName: 'Additional Options',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
options: [
{
displayName: 'Include Token Usage',
name: 'includeUsage',
type: 'boolean',
default: false,
description: 'Whether to include token usage information in the response',
},
],
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
let agent = '';
let query = '';
let model = '';
let additionalFields = {};
try {
agent = this.getNodeParameter('agent', i);
query = this.getNodeParameter('query', i);
const predictionMarketsMode = this.getNodeParameter('predictionMarketsMode', i, 'default');
additionalFields = this.getNodeParameter('additionalFields', i, {});
model = resolveModel(agent, predictionMarketsMode);
if (!query || query.trim().length === 0) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Query is required and cannot be empty', {
itemIndex: i,
});
}
if (agent === PREDICTION_MARKETS_AGENT && !KALSHI_URL_PATTERN.test(query)) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Prediction markets requests must include a Kalshi market URL in the query', {
itemIndex: i,
});
}
const requestOptions = {
url: 'https://api-gateway.octagonagents.com/v1/responses',
method: 'POST',
body: {
model,
input: query,
},
json: true,
headers: {
'Content-Type': 'application/json',
'User-Agent': `${packageInfo.name}/${packageInfo.version}`,
},
};
let response;
try {
response = (await this.helpers.httpRequestWithAuthentication.call(this, 'octagonApi', requestOptions));
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error, {
itemIndex: i,
});
}
let analysis = '';
let citations = [];
let usage;
let cacheData;
if (response.output && response.output.length > 0) {
const outputItem = response.output[0];
if (outputItem.content && outputItem.content.length > 0) {
const contentItem = outputItem.content[0];
if (contentItem.text) {
analysis = contentItem.text;
}
if (contentItem.annotations) {
citations = contentItem.annotations;
}
}
}
if (response.usage) {
usage = response.usage;
}
if (model.endsWith(':cache') && analysis.trim().length > 0) {
cacheData = parseCachePayload(analysis);
if (!cacheData) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Prediction markets cache mode returned invalid JSON', {
itemIndex: i,
});
}
}
const outputData = {
agent,
model,
query,
analysis,
sources: citations,
metadata: {
apiType: 'responses',
timestamp: new Date().toISOString(),
},
};
if (cacheData) {
outputData.cacheData = cacheData;
}
if (additionalFields.includeUsage === true && usage) {
outputData.usage = usage;
}
returnData.push({
json: outputData,
});
}
catch (error) {
if (this.continueOnFail()) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
returnData.push({
json: {
error: true,
message: errorMessage,
query,
agent,
model,
timestamp: new Date().toISOString(),
},
pairedItem: {
item: i,
},
});
continue;
}
if (error instanceof n8n_workflow_1.NodeApiError || error instanceof n8n_workflow_1.NodeOperationError) {
throw error;
}
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
itemIndex: i,
});
}
}
return this.prepareOutputData(returnData);
}
}
exports.OctagonAgents = OctagonAgents;
//# sourceMappingURL=OctagonAgents.node.js.map