Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Components - summit #11996

Merged
merged 4 commits into from
May 22, 2024
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
29 changes: 29 additions & 0 deletions components/summit/actions/list-models/list-models.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import summit from "../../summit.app.mjs";

export default {
key: "summit-list-models",
name: "List Models",
description: "Returns a list of models from Summit. [See the documentation](https://summit.readme.io/reference/apps)",
version: "0.0.1",
type: "action",
props: {
summit,
},
async run({ $ }) {
const results = this.summit.paginate({
resourceFn: this.summit.listModels,
resourceType: "apps",
args: {
$,
},
});
const models = [];
for await (const model of results) {
models.push(model);
}
$.export("$summary", `Successfully retrieved ${models.length} model${models.length === 1
? ""
: "s"}`);
return models;
},
};
69 changes: 69 additions & 0 deletions components/summit/actions/run-model/run-model.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import summit from "../../summit.app.mjs";

export default {
key: "summit-run-model",
name: "Run Model",
description: "Executes a model within Summit and captures the response fields. [See the documentation](https://summit.readme.io/reference/model-api)",
version: "0.0.1",
type: "action",
props: {
summit,
model: {
propDefinition: [
summit,
"model",
],
reloadProps: true,
},
experimentalFlatten: {
type: "integer",
label: "Experimental Flatten",
description: "This allows you to choose the index of the column you'd like to pull from the grid. -1 is the last column, which is useful for grabbing the last slice of a time series model, like a forecast.",
optional: true,
},
},
async additionalProps() {
const props = {};
if (!this.model) {
return props;
}
const { parameters } = await this.summit.getModel({
model: this.model,
});
for (const parameter of parameters) {
props[parameter.name] = {
type: "string",
label: `${parameter.name}`,
default: `${parameter.default_value}`,
};
if (parameter.value_choices) {
props[parameter.name].options = parameter.value_choices;
}
}
return props;
},
async run({ $ }) {
const { parameters } = await this.summit.getModel({
model: this.model,
});
const parametersObj = {};
for (const parameter of parameters) {
parametersObj[parameter.name] = this[parameter.name];
}
const data = {
parameters: parametersObj,
};
if (this.experimentalFlatten !== undefined) {
data.output = {
"__experimental_flatten": this.experimentalFlatten,
};
}
const response = await this.summit.runModel({
$,
model: this.model,
data,
});
$.export("$summary", `Successfully executed model \`${(this.model).split("/").pop()}\``);
return response;
},
};
7 changes: 5 additions & 2 deletions components/summit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/summit",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Summit Components",
"main": "summit.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.5"
}
}
}
48 changes: 48 additions & 0 deletions components/summit/sources/new-model-added/new-model-added.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import summit from "../../summit.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
key: "summit-new-model-added",
name: "New Model Added",
description: "Emit new event when a new model is added to your organization in Summit. [See the documentation](https://summit.readme.io/reference/apps)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
summit,
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
methods: {
generateMeta(model) {
return {
id: model.id,
summary: `New Modle ${model.name}`,
ts: Date.now(),
};
},
async processEvent(max) {
const results = this.summit.paginate({
resourceFn: this.summit.listModels,
resourceType: "apps",
max,
});
for await (const model of results) {
const meta = this.generateMeta(model);
this.$emit(model, meta);
}
},
},
async run() {
await this.processEvent();
},
};
95 changes: 91 additions & 4 deletions components/summit/summit.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,98 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "summit",
propDefinitions: {},
propDefinitions: {
model: {
type: "string",
label: "Model",
description: "The identifier model to run in the format `:organization_slug/:external_id/:app_slug`",
async options({ prevContext }) {
const args = prevContext?.next
? {
url: prevContext.next,
}
: {};
const {
apps, next,
} = await this.listModels(args);
return {
options: apps?.map(({
app_identifier: value, name: label,
}) => ({
value,
label,
})) || [],
context: {
next,
},
};
},
},

},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.usesummit.com/v1";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"x-api-key": `${this.$auth.api_key}`,
},
...otherOpts,
});
},
listModels(opts = {}) {
return this._makeRequest({
path: "/apps",
...opts,
});
},
getModel({
model, ...opts
}) {
return this._makeRequest({
path: `/${model}/`,
...opts,
});
},
runModel({
model, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/${model}/`,
...opts,
});
},
async *paginate({
resourceFn,
resourceType,
args = {},
max,
}) {
let next, count = 0;
do {
const results = await resourceFn(args);
const items = results[resourceType];
for (const item of items) {
yield item;
count++;
if (max && count >= max) {
return;
}
}
next = results?.next;
args.url = next;
} while (next);
},
},
};
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading