Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .oxlintrc.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
// - perf (11 rules): Performance-related issues
// - style (168 rules): Code style rules
// Note: restriction category should be enabled per-rule basis
//
// pedantic and style are off. oxlint only reads .oxlintrc.jsonc from 1.52.0, so until the nix
// flake moved to 1.88 this file was never loaded and CI ran oxlint's 104 default rules. Turned on
// as written, the two categories report about 4,000 findings in code never held to them; adopting
// them is its own change. The rules named one by one below still apply.
"categories": {
"correctness": "error",
"suspicious": "error",
"pedantic": "error",
"pedantic": "off",
"perf": "error",
"style": "error",
"style": "off",
},
"rules": {
// ===================
Expand Down Expand Up @@ -139,7 +144,7 @@
// Import Rules
// ===================
// Enforce top-level type specifier style
"import/consistent-type-specifier-style": ["error", "top-level"],
"import/consistent-type-specifier-style": ["error", "prefer-top-level"],
// ===================
// Unicorn Rules
// ===================
Expand Down
9 changes: 5 additions & 4 deletions examples/ai-sdk-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ import { StackOneToolSet } from '@stackone/ai';
import { generateText, stepCountIs } from 'ai';

const apiKey = process.env.STACKONE_API_KEY;
if (!apiKey) {
if (apiKey === undefined || apiKey === '') {
console.error('STACKONE_API_KEY environment variable is required');
process.exit(1);
}
if (!process.env.OPENAI_API_KEY) {
if ((process.env.OPENAI_API_KEY ?? '') === '') {
console.log('Skipping: OPENAI_API_KEY is not set');
process.exit(0);
}

const aiSdkIntegration = async (): Promise<void> => {
// Initialize StackOne — reads STACKONE_API_KEY from env. The account id is passed explicitly;
// without one, the toolset uses every active shared account linked to the key
const toolset = new StackOneToolSet({ accountId: process.env.STACKONE_ACCOUNT_ID || undefined });
const accountId = process.env.STACKONE_ACCOUNT_ID;
const toolset = new StackOneToolSet({ accountId: accountId === '' ? undefined : accountId });

// Filter to specific tools to keep token usage manageable
const tools = await toolset.fetchTools({
Expand All @@ -53,7 +54,7 @@ const aiSdkIntegration = async (): Promise<void> => {
console.log(`Steps taken: ${steps.length}`);

for (const step of steps) {
if (step.toolCalls && step.toolCalls.length > 0) {
if (step.toolCalls.length > 0) {
for (const toolCall of step.toolCalls) {
console.log(` Tool call: ${toolCall.toolName}`);
console.log(` Arguments: ${JSON.stringify((toolCall as Record<string, unknown>).args)}`);
Expand Down
7 changes: 4 additions & 3 deletions examples/anthropic-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import Anthropic from '@anthropic-ai/sdk';
import { StackOneToolSet } from '@stackone/ai';

const apiKey = process.env.STACKONE_API_KEY;
if (!apiKey) {
if (apiKey === undefined || apiKey === '') {
console.error('STACKONE_API_KEY environment variable is required');
process.exit(1);
}
if (!process.env.ANTHROPIC_API_KEY) {
if ((process.env.ANTHROPIC_API_KEY ?? '') === '') {
console.log('Skipping: ANTHROPIC_API_KEY is not set');
process.exit(0);
}

const anthropicIntegration = async (): Promise<void> => {
// Initialize StackOne — reads STACKONE_API_KEY from env. The account id is passed explicitly;
// without one, the toolset uses every active shared account linked to the key
const toolset = new StackOneToolSet({ accountId: process.env.STACKONE_ACCOUNT_ID || undefined });
const accountId = process.env.STACKONE_ACCOUNT_ID;
const toolset = new StackOneToolSet({ accountId: accountId === '' ? undefined : accountId });

@cubic-dev-ai cubic-dev-ai Bot Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This converts an explicitly empty STACKONE_ACCOUNT_ID to undefined, bypassing the constructor’s ToolSetConfigError and widening the toolset to every active account. Pass accountId through so the constructor rejects the empty value.

(Based on your team's feedback about empty account IDs.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At examples/anthropic-integration.ts, line 23:

<comment>This converts an explicitly empty `STACKONE_ACCOUNT_ID` to `undefined`, bypassing the constructor’s `ToolSetConfigError` and widening the toolset to every active account. Pass `accountId` through so the constructor rejects the empty value.

(Based on your team's feedback about empty account IDs.) </comment>

<file context>
@@ -7,19 +7,20 @@ import Anthropic from '@anthropic-ai/sdk';
 	// without one, the toolset uses every active shared account linked to the key
-	const toolset = new StackOneToolSet({ accountId: process.env.STACKONE_ACCOUNT_ID || undefined });
+	const accountId = process.env.STACKONE_ACCOUNT_ID;
+	const toolset = new StackOneToolSet({ accountId: accountId === '' ? undefined : accountId });
 
 	// Filter for any relevant tools
</file context>
Suggested change
const toolset = new StackOneToolSet({ accountId: accountId === '' ? undefined : accountId });
const toolset = new StackOneToolSet({ accountId });
Fix with cubic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a change: before this PR the line was accountId: process.env.STACKONE_ACCOUNT_ID || undefined, which also turns an empty value into undefined. The rewrite keeps that behaviour exactly; changing what the example does with an empty variable is out of scope for a lint repair.


// Filter for any relevant tools
const tools = await toolset.fetchTools({
Expand Down
16 changes: 11 additions & 5 deletions examples/auth-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
import process from 'node:process';
import { StackOneToolSet } from '@stackone/ai';

if (!process.env.STACKONE_API_KEY) {
if ((process.env.STACKONE_API_KEY ?? '') === '') {
console.error('Set STACKONE_API_KEY to run this example.');
process.exit(1);
}

/** STACKONE_ACCOUNT_ID, or undefined when it is unset or empty. */
const envAccountId = (): string | undefined => {
const accountId = process.env.STACKONE_ACCOUNT_ID;
return accountId === '' ? undefined : accountId;
};

// --- 1. API Key setup ---
const apiKeyFromEnv = async (): Promise<void> => {
console.log('=== 1a. API Key from environment ===\n');
Expand Down Expand Up @@ -54,8 +60,8 @@ const accountIdFromEnv = async (): Promise<void> => {

// The SDK only reads the API key from env; read the account id yourself and pass it.
// Unset or empty, it is undefined and the toolset discovers every active shared account instead.
const accountId = process.env.STACKONE_ACCOUNT_ID || undefined;
console.log(` STACKONE_ACCOUNT_ID is ${accountId ? 'set' : 'not set'}`);
const accountId = envAccountId();
console.log(` STACKONE_ACCOUNT_ID is ${accountId === undefined ? 'not set' : 'set'}`);

const toolset = new StackOneToolSet({ accountId });
const tools = await toolset.fetchTools();
Expand All @@ -66,7 +72,7 @@ const accountIdFromEnv = async (): Promise<void> => {
const accountIdInConstructor = async (): Promise<void> => {
console.log('=== 3. Account ID in constructor ===\n');

const accountId = process.env.STACKONE_ACCOUNT_ID || 'my-account';
const accountId = envAccountId() ?? 'my-account';
const toolset = new StackOneToolSet({ accountId });
const tools = await toolset.fetchTools();
console.log(` Loaded ${tools.toOpenAI().length} tools for configured account\n`);
Expand All @@ -76,7 +82,7 @@ const accountIdInConstructor = async (): Promise<void> => {
const setAccountsGlobally = async (): Promise<void> => {
console.log('=== 4. setAccounts() — global account list ===\n');

const accountId = process.env.STACKONE_ACCOUNT_ID || 'my-account';
const accountId = envAccountId() ?? 'my-account';
const toolset = new StackOneToolSet();
toolset.setAccounts([accountId]);
console.log(' Called setAccounts() with configured account');
Expand Down
9 changes: 5 additions & 4 deletions examples/claude-agent-sdk-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ import { query } from '@anthropic-ai/claude-agent-sdk';
import { StackOneToolSet } from '@stackone/ai';

const apiKey = process.env.STACKONE_API_KEY;
if (!apiKey) {
if (apiKey === undefined || apiKey === '') {
console.error('STACKONE_API_KEY environment variable is required');
process.exit(1);
}
if (!process.env.ANTHROPIC_API_KEY) {
if ((process.env.ANTHROPIC_API_KEY ?? '') === '') {
console.log('Skipping: ANTHROPIC_API_KEY is not set');
process.exit(0);
}

const claudeAgentSdkIntegration = async (): Promise<void> => {
// Initialize StackOne — reads STACKONE_API_KEY from env. The account id is passed explicitly;
// without one, the toolset uses every active shared account linked to the key
const toolset = new StackOneToolSet({ accountId: process.env.STACKONE_ACCOUNT_ID || undefined });
const accountId = process.env.STACKONE_ACCOUNT_ID;
const toolset = new StackOneToolSet({ accountId: accountId === '' ? undefined : accountId });

// Fetch tools from StackOne and convert to Claude Agent SDK format
const tools = await toolset.fetchTools();
Expand All @@ -39,7 +40,7 @@ const claudeAgentSdkIntegration = async (): Promise<void> => {
options: {
model: 'claude-sonnet-4-5-20250929',
mcpServers: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Compatible MCP server type
// oxlint-disable-next-line typescript/no-explicit-any, typescript/no-unsafe-type-assertion -- Compatible MCP server type
'stackone-tools': mcpServer as any,
},
// Disable built-in tools, only use our custom tools
Expand Down
31 changes: 20 additions & 11 deletions examples/openai-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@ import { StackOneToolSet } from '@stackone/ai';
import OpenAI from 'openai';

const apiKey = process.env.STACKONE_API_KEY;
if (!apiKey) {
if (apiKey === undefined || apiKey === '') {
console.error('STACKONE_API_KEY environment variable is required');
process.exit(1);
}
if (!process.env.OPENAI_API_KEY) {
if ((process.env.OPENAI_API_KEY ?? '') === '') {
console.log('Skipping: OPENAI_API_KEY is not set');
process.exit(0);
}

/** The text of a completion's first choice, or `''` when it has none. */
const replyText = (completion: OpenAI.ChatCompletion): string =>
completion.choices[0]?.message.content ?? '';

const printToolCalls = (toolCalls: OpenAI.ChatCompletionMessageToolCall[]): void => {
for (const toolCall of toolCalls) {
if (toolCall.type === 'function') {
console.log(` Tool: ${toolCall.function.name}`);
console.log(` Arguments: ${toolCall.function.arguments}`);
}
}
};

const openaiIntegration = async (): Promise<void> => {
// Initialize StackOne — reads STACKONE_API_KEY from env. The account id is passed explicitly;
// without one, the toolset uses every active shared account linked to the key
const toolset = new StackOneToolSet({ accountId: process.env.STACKONE_ACCOUNT_ID || undefined });
const accountId = process.env.STACKONE_ACCOUNT_ID;
const toolset = new StackOneToolSet({ accountId: accountId === '' ? undefined : accountId });

// Filter to specific tools to stay within OpenAI's 128-tool limit
const tools = await toolset.fetchTools({
Expand Down Expand Up @@ -51,16 +65,11 @@ const openaiIntegration = async (): Promise<void> => {
const message = response.choices[0]?.message;
const toolCalls = message?.tool_calls ?? [];
console.log(`Tool calls made: ${toolCalls.length}`);
if (!message || toolCalls.length === 0) {
if (message === undefined || toolCalls.length === 0) {
return;
}

for (const toolCall of toolCalls) {
if (toolCall.type === 'function') {
console.log(` Tool: ${toolCall.function.name}`);
console.log(` Arguments: ${toolCall.function.arguments}`);
}
}
printToolCalls(toolCalls);

// Run the tool calls and hand the results back. The assistant turn must come before its tool
// results, or OpenAI returns a 400. A failed call becomes a tool message the model can read.
Expand All @@ -71,7 +80,7 @@ const openaiIntegration = async (): Promise<void> => {
messages,
tools: openAITools,
});
console.log(`Answer: ${final.choices[0]?.message.content ?? ''}`);
console.log(`Answer: ${replyText(final)}`);
};

// Run the example
Expand Down
7 changes: 4 additions & 3 deletions examples/openai-responses-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import { StackOneToolSet } from '@stackone/ai';
import OpenAI from 'openai';

const apiKey = process.env.STACKONE_API_KEY;
if (!apiKey) {
if (apiKey === undefined || apiKey === '') {
console.error('STACKONE_API_KEY environment variable is required');
process.exit(1);
}
if (!process.env.OPENAI_API_KEY) {
if ((process.env.OPENAI_API_KEY ?? '') === '') {
console.log('Skipping: OPENAI_API_KEY is not set');
process.exit(0);
}

const openaiResponsesIntegration = async (): Promise<void> => {
// Initialize StackOne — reads STACKONE_API_KEY from env. The account id is passed explicitly;
// without one, the toolset uses every active shared account linked to the key
const toolset = new StackOneToolSet({ accountId: process.env.STACKONE_ACCOUNT_ID || undefined });
const accountId = process.env.STACKONE_ACCOUNT_ID;
const toolset = new StackOneToolSet({ accountId: accountId === '' ? undefined : accountId });

// Fetch tools via MCP
const tools = await toolset.fetchTools({
Expand Down
28 changes: 19 additions & 9 deletions examples/search-and-execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,40 @@

import process from 'node:process';
import { StackOneError, StackOneToolSet, ToolSetError } from '@stackone/ai';
import type { SearchResult, StackOneAccount } from '@stackone/ai';

if (!process.env.STACKONE_API_KEY) {
if ((process.env.STACKONE_API_KEY ?? '') === '') {
console.error('STACKONE_API_KEY environment variable is required');
process.exit(1);
}

const printAccounts = (accounts: StackOneAccount[]): void => {
for (const account of accounts) {
console.log(`${account.id} ${account.provider ?? '?'} ${account.status ?? '?'}`);
}
};

const printRankedMatches = (actions: SearchResult[]): void => {
console.log('\nRanked matches:');
for (const action of actions) {
// oxlint-disable-next-line typescript/no-unnecessary-type-conversion -- a server can send the score as a numeric string
console.log(` ${Number(action.similarity_score ?? 0).toFixed(3)} ${action.action_id}`);
}
};

const searchAndExecute = async (): Promise<void> => {
const toolset = new StackOneToolSet();

for (const account of await toolset.fetchAccounts()) {
console.log(`${account.id} ${account.provider ?? '?'} ${account.status ?? '?'}`);
}
printAccounts(await toolset.fetchAccounts());

const actions = await toolset.search('list recent comments', { topK: 3 });
const [best] = actions;
if (!best) {
if (best === undefined) {
console.error('No actions matched. Try a different query, or link an account.');
process.exit(1);
}

console.log('\nRanked matches:');
for (const action of actions) {
console.log(` ${Number(action.similarity_score ?? 0).toFixed(3)} ${action.action_id}`);
}
printRankedMatches(actions);

// input_schema is how you find out what an action accepts. Build the call from it and from
// example_request: arguments that do not match are dropped by the server without an error,
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# runtime
nodejs_24
pnpm_10
typescript-go
typescript

# formatting and linting tools
similarity
Expand Down
38 changes: 23 additions & 15 deletions mocks/handlers.openai.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import { http, HttpResponse } from 'msw';
import { extractTextFromInput } from './handlers.utils';
import { bodyField, extractTextFromInput, isRecord, offersTools } from './handlers.utils';

/** The first user message of a chat completion that mentions an employee, or `''`. */
const employeeQuestion = (messages: unknown): string => {
if (!Array.isArray(messages)) {
return '';
}
const candidates: unknown[] = messages;
for (const message of candidates) {
if (isRecord(message) && message.role === 'user' && typeof message.content === 'string') {
if (message.content.includes('employee')) {
return message.content;
}
}
}
return '';
};

/**
* OpenAI API endpoints for AI SDK and OpenAI integration examples
*/
export const openaiHandlers = [
// OpenAI Responses API (used by AI SDK)
http.post('https://api.openai.com/v1/responses', async ({ request }) => {
const body = (await request.json()) as {
input?: unknown;
tools?: Array<{ name?: string }>;
};
const userMessage = extractTextFromInput(body.input);
const hasTools = body.tools && body.tools.length > 0;
const body = await request.json();
const userMessage = extractTextFromInput(bodyField(body, 'input'));
const hasTools = offersTools(body);

// For ai-sdk-integration.ts
if (hasTools && userMessage.includes('Get all details')) {
Expand Down Expand Up @@ -115,14 +128,9 @@ export const openaiHandlers = [

// OpenAI Chat Completions API (used by OpenAI SDK directly)
http.post('https://api.openai.com/v1/chat/completions', async ({ request }) => {
const body = (await request.json()) as {
messages?: Array<{ content?: string; role?: string }>;
tools?: Array<{ function?: { name?: string } }>;
};
const userMessage =
body.messages?.find((m) => m.role === 'user' && m.content?.includes('employee'))?.content ??
'';
const hasTools = body.tools && body.tools.length > 0;
const body = await request.json();
const userMessage = employeeQuestion(bodyField(body, 'messages'));
const hasTools = offersTools(body);

// For openai-integration.ts - returns tool call for bamboohr_get_employee
if (hasTools && userMessage.includes('c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA')) {
Expand Down
2 changes: 1 addition & 1 deletion mocks/handlers.stackone-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const mockAccounts = [

export const stackoneAccountsHandlers = [
http.get(`${TEST_BASE_URL}/accounts`, ({ request }) => {
if (!request.headers.get('Authorization')?.startsWith('Basic ')) {
if (request.headers.get('Authorization')?.startsWith('Basic ') !== true) {
return HttpResponse.json({ message: 'Unauthorized' }, { status: 401 });
}
return HttpResponse.json(mockAccounts);
Expand Down
Loading
Loading