Skip to content

Commit

Permalink
Merge branch 'master' into fix-cli-parity-4
Browse files Browse the repository at this point in the history
  • Loading branch information
plxity authored Dec 12, 2024
2 parents 0dec6b8 + 259113e commit c387b93
Show file tree
Hide file tree
Showing 21 changed files with 372 additions and 26 deletions.
4 changes: 0 additions & 4 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@
{
"name": "All Tools",
"url": "https://composio.dev/tools"
},
{
"name": "Chat with Repo",
"url": "https://dub.composio.dev/composio-chat-with-repo"
}
],
"navigation": [
Expand Down
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composio-core",
"version": "0.4.1-beta",
"version": "0.4.3-beta",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
44 changes: 44 additions & 0 deletions js/src/cli/execute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Command } from "commander";
import client from "../sdk/client/client";
import chalk from "chalk";
import { getOpenAPIClient } from "../sdk/utils/config";

export default class ExecuteCommand {
private program: Command;
constructor(program: Command) {
this.program = program;
this.program
.command("execute <action>")
.description("Execute a Composio action")
.option("-p, --params <params>", "Action parameters as a JSON string")
.action(this.handleAction.bind(this));
}
private async handleAction(
action: string,
options: {
params?: string;
}
): Promise<void> {
getOpenAPIClient();
const { params } = options;
try {
const res = await client.actionsV2.executeActionV2({
body: params ? JSON.parse(params) : {},
path: {
actionId: action,
},
});
console.log(
chalk.green(
"Action executed successfully",
JSON.stringify(res?.data?.data, null, 2)
)
);
} catch (error) {
console.log(
chalk.red(`Error executing action: ${(error as Error).message}`)
);
return;
}
}
}
2 changes: 2 additions & 0 deletions js/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import logout from "./logout";
import triggers from "./triggers";
import whoami from "./whoami";
import actions from "./actions";
import execute from "./execute";

// SDK Imports
import { TELEMETRY_EVENTS } from "../sdk/utils/telemetry/events";
Expand All @@ -30,6 +31,7 @@ new integrations(program);
new triggers(program);
new add(program);
new actions(program);
new execute(program);

function formatLine(content: string): string {
return `${content}`;
Expand Down
2 changes: 1 addition & 1 deletion js/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ACTIONS = {
// actions list end here
};

const COMPOSIO_VERSION = `0.4.1-beta`;
const COMPOSIO_VERSION = `0.4.3-beta`;

module.exports = {
APPS,
Expand Down
19 changes: 18 additions & 1 deletion js/src/frameworks/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
import { COMPOSIO_BASE_URL } from "../sdk/client/core/OpenAPI";
import { WorkspaceConfig } from "../env/config";
import { Workspace } from "../env";
import { ActionsListResponseDTO } from "../sdk/client";
import { TELEMETRY_LOGGER } from "../sdk/utils/telemetry";
import { TELEMETRY_EVENTS } from "../sdk/utils/telemetry/events";

// Type definitions
type Optional<T> = T | null;
Expand All @@ -21,6 +22,7 @@ export class CloudflareToolSet extends BaseComposioToolSet {
// Class constants
static FRAMEWORK_NAME = "cloudflare";
static DEFAULT_ENTITY_ID = "default";
fileName: string = "js/src/frameworks/cloudflare.ts";

/**
* Initialize a new CloudflareToolSet instance
Expand Down Expand Up @@ -58,6 +60,11 @@ export class CloudflareToolSet extends BaseComposioToolSet {
usecaseLimit?: Optional<number>;
filterByAvailableApps?: Optional<boolean>;
}): Promise<Sequence<AiTextGenerationToolInput>> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "getTools",
file: this.fileName,
params: filters,
});
const actions = await this.getToolsSchema(filters);
return (
actions.map((action) => {
Expand Down Expand Up @@ -99,6 +106,11 @@ export class CloudflareToolSet extends BaseComposioToolSet {
},
entityId: Optional<string> = null
): Promise<string> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "executeToolCall",
file: this.fileName,
params: { tool, entityId },
});
return JSON.stringify(
await this.executeAction({
action: tool.name,
Expand All @@ -122,6 +134,11 @@ export class CloudflareToolSet extends BaseComposioToolSet {
result: AiTextGenerationOutput,
entityId: Optional<string> = null
): Promise<Sequence<string>> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "handleToolCall",
file: this.fileName,
params: { result, entityId },
});
const outputs = [];
if ("tool_calls" in result && Array.isArray(result.tool_calls)) {
for (const tool_call of result.tool_calls) {
Expand Down
9 changes: 9 additions & 0 deletions js/src/frameworks/langchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { COMPOSIO_BASE_URL } from "../sdk/client/core/OpenAPI";
import type { Optional, Dict, Sequence } from "../sdk/types";
import { WorkspaceConfig } from "../env/config";
import { Workspace } from "../env";
import { TELEMETRY_EVENTS } from "../sdk/utils/telemetry/events";
import { TELEMETRY_LOGGER } from "../sdk/utils/telemetry";

export class LangchainToolSet extends BaseComposioToolSet {
/**
Expand All @@ -13,6 +15,7 @@ export class LangchainToolSet extends BaseComposioToolSet {
*/
static FRAMEWORK_NAME = "langchain";
static DEFAULT_ENTITY_ID = "default";
fileName: string = "js/src/frameworks/langchain.ts";

constructor(
config: {
Expand Down Expand Up @@ -72,6 +75,12 @@ export class LangchainToolSet extends BaseComposioToolSet {
},
entityId: Optional<string> = null
): Promise<Sequence<DynamicStructuredTool>> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "getTools",
file: this.fileName,
params: { filters, entityId },
});

const tools = await this.getToolsSchema(filters, entityId);
return tools.map((tool) => this._wrapTool(tool, entityId || this.entityId));
}
Expand Down
37 changes: 37 additions & 0 deletions js/src/frameworks/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Workspace } from "../env";
import logger from "../utils/logger";
import { ActionsListResponseDTO } from "../sdk/client";
import { Stream } from "openai/streaming";
import { TELEMETRY_LOGGER } from "../sdk/utils/telemetry";
import { TELEMETRY_EVENTS } from "../sdk/utils/telemetry/events";

type Optional<T> = T | null;
type Sequence<T> = Array<T>;
Expand All @@ -15,6 +17,8 @@ export class OpenAIToolSet extends BaseComposioToolSet {
static FRAMEWORK_NAME = "openai";
static DEFAULT_ENTITY_ID = "default";

fileName: string = "js/src/frameworks/openai.ts";

/**
* Composio toolset for OpenAI framework.
*
Expand Down Expand Up @@ -51,6 +55,12 @@ export class OpenAIToolSet extends BaseComposioToolSet {
},
entityId?: Optional<string>
): Promise<Sequence<OpenAI.ChatCompletionTool>> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "getTools",
file: this.fileName,
params: filters,
});

const mainActions = await this.getToolsSchema(filters, entityId);
return (
mainActions.map(
Expand All @@ -74,6 +84,11 @@ export class OpenAIToolSet extends BaseComposioToolSet {
tool: OpenAI.ChatCompletionMessageToolCall,
entityId: Optional<string> = null
): Promise<string> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "executeToolCall",
file: this.fileName,
params: { tool, entityId },
});
return JSON.stringify(
await this.executeAction({
action: tool.function.name,
Expand All @@ -87,6 +102,11 @@ export class OpenAIToolSet extends BaseComposioToolSet {
chatCompletion: OpenAI.ChatCompletion,
entityId: Optional<string> = null
): Promise<Sequence<string>> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "handleToolCall",
file: this.fileName,
params: { chatCompletion, entityId },
});
const outputs = [];
for (const message of chatCompletion.choices) {
if (message.message.tool_calls) {
Expand All @@ -104,6 +124,11 @@ export class OpenAIToolSet extends BaseComposioToolSet {
): Promise<
Array<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput>
> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "handleAssistantMessage",
file: this.fileName,
params: { run, entityId },
});
const tool_calls =
run.required_action?.submit_tool_outputs?.tool_calls || [];
const tool_outputs: Array<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput> =
Expand Down Expand Up @@ -134,6 +159,12 @@ export class OpenAIToolSet extends BaseComposioToolSet {
thread: OpenAI.Beta.Threads.Thread,
entityId: string | null = null
): AsyncGenerator<any, void, unknown> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "waitAndHandleAssistantStreamToolCalls",
file: this.fileName,
params: { client, runStream, thread, entityId },
});

let runId = null;

// Start processing the runStream events
Expand Down Expand Up @@ -213,6 +244,12 @@ export class OpenAIToolSet extends BaseComposioToolSet {
thread: OpenAI.Beta.Threads.Thread,
entityId: Optional<string> = null
): Promise<OpenAI.Beta.Threads.Run> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "waitAndHandleAssistantToolCalls",
file: this.fileName,
params: { client, run, thread, entityId },
});

while (["queued", "in_progress", "requires_action"].includes(run.status)) {
logger.debug(`Current run status: ${run.status}`);
const tool_outputs = await this.handleAssistantMessage(
Expand Down
15 changes: 15 additions & 0 deletions js/src/frameworks/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { jsonSchemaToModel } from "../utils/shared";
import { z } from "zod";
import { CEG } from "../sdk/utils/error";
import { SDK_ERROR_CODES } from "../sdk/utils/errors/src/constants";
import { TELEMETRY_LOGGER } from "../sdk/utils/telemetry";
import { TELEMETRY_EVENTS } from "../sdk/utils/telemetry/events";
type Optional<T> = T | null;

const zExecuteToolCallParams = z.object({
Expand All @@ -20,6 +22,7 @@ const zExecuteToolCallParams = z.object({
});

export class VercelAIToolSet extends BaseComposioToolSet {
fileName: string = "js/src/frameworks/vercel.ts";
constructor(
config: {
apiKey?: Optional<string>;
Expand Down Expand Up @@ -61,6 +64,12 @@ export class VercelAIToolSet extends BaseComposioToolSet {
usecaseLimit?: Optional<number>;
filterByAvailableApps?: Optional<boolean>;
}): Promise<{ [key: string]: any }> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "getTools",
file: this.fileName,
params: filters,
});

const {
apps,
tags,
Expand Down Expand Up @@ -92,6 +101,12 @@ export class VercelAIToolSet extends BaseComposioToolSet {
tool: { name: string; arguments: unknown },
entityId: Optional<string> = null
): Promise<string> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "executeToolCall",
file: this.fileName,
params: { tool, entityId },
});

return JSON.stringify(
await this.executeAction({
action: tool.name,
Expand Down
13 changes: 12 additions & 1 deletion js/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class Composio {
integrations: Integrations;
activeTriggers: ActiveTriggers;

fileName: string = "js/src/sdk/index.ts";

/**
* Initializes a new instance of the Composio class.
*
Expand All @@ -45,7 +47,6 @@ export class Composio {
baseUrl,
apiKey
);
const loggingLevel = getLogLevel();

ComposioSDKContext.apiKey = apiKeyParsed;
ComposioSDKContext.baseURL = baseURLParsed;
Expand Down Expand Up @@ -121,6 +122,11 @@ export class Composio {
* @returns {Entity} An instance of the Entity class.
*/
getEntity(id: string = "default"): Entity {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "getEntity",
file: this.fileName,
params: { id },
});
return new Entity(this.backendClient, id);
}

Expand Down Expand Up @@ -148,6 +154,11 @@ export class Composio {
| "BEARER_TOKEN"
| "BASIC_WITH_JWT";
}> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "getExpectedParamsForUser",
file: this.fileName,
params: params,
});
const { app } = params;
let { integrationId } = params;
if (integrationId === null && app === null) {
Expand Down
Loading

0 comments on commit c387b93

Please sign in to comment.