@ubiquity-os/plugin-sdk 3.1.3 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers.d.mts +59 -0
- package/dist/helpers.d.ts +59 -0
- package/dist/helpers.js +86 -0
- package/dist/helpers.mjs +57 -0
- package/dist/index.js +50 -1
- package/dist/index.mjs +50 -1
- package/package.json +9 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
type OpenRouterError = {
|
|
2
|
+
error: {
|
|
3
|
+
message: string;
|
|
4
|
+
code: number;
|
|
5
|
+
metadata?: {
|
|
6
|
+
provider_name: string;
|
|
7
|
+
raw: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
reasons: string[];
|
|
10
|
+
flagged_input: string;
|
|
11
|
+
provider_name: string;
|
|
12
|
+
model_slug: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type OpenRouterModel = {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
created: number;
|
|
20
|
+
description: string;
|
|
21
|
+
context_length: number;
|
|
22
|
+
architecture: {
|
|
23
|
+
modality: string;
|
|
24
|
+
tokenizer: string;
|
|
25
|
+
instruct_type?: string;
|
|
26
|
+
};
|
|
27
|
+
top_provider: {
|
|
28
|
+
context_length: number;
|
|
29
|
+
/** `null` means it's the same as the context_length */
|
|
30
|
+
max_completion_tokens: number | null;
|
|
31
|
+
is_moderated: boolean;
|
|
32
|
+
};
|
|
33
|
+
pricing: {
|
|
34
|
+
prompt: string;
|
|
35
|
+
completion: string;
|
|
36
|
+
image: string;
|
|
37
|
+
request: string;
|
|
38
|
+
input_cache_read: string;
|
|
39
|
+
input_cache_write: string;
|
|
40
|
+
web_search: string;
|
|
41
|
+
internal_reasoning: string;
|
|
42
|
+
};
|
|
43
|
+
per_request_limits?: Record<string, unknown>;
|
|
44
|
+
};
|
|
45
|
+
declare function getOpenRouterModels(): Promise<OpenRouterModel[]>;
|
|
46
|
+
declare function getOpenRouterModelTokenLimits(modelId: string): Promise<{
|
|
47
|
+
contextLength: number;
|
|
48
|
+
maxCompletionTokens: number;
|
|
49
|
+
} | null>;
|
|
50
|
+
|
|
51
|
+
interface RetryOptions {
|
|
52
|
+
maxRetries: number;
|
|
53
|
+
onError?: (error: unknown) => Promise<void> | void;
|
|
54
|
+
/** Return `false` to stop retrying, `true` to automatically delay the next retry, or a number to set the delay before the next retry */
|
|
55
|
+
isErrorRetryable?: (error: unknown) => Promise<boolean | number> | boolean | number;
|
|
56
|
+
}
|
|
57
|
+
declare function retry<T>(fn: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
58
|
+
|
|
59
|
+
export { type OpenRouterError, type OpenRouterModel, getOpenRouterModelTokenLimits, getOpenRouterModels, retry };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
type OpenRouterError = {
|
|
2
|
+
error: {
|
|
3
|
+
message: string;
|
|
4
|
+
code: number;
|
|
5
|
+
metadata?: {
|
|
6
|
+
provider_name: string;
|
|
7
|
+
raw: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
reasons: string[];
|
|
10
|
+
flagged_input: string;
|
|
11
|
+
provider_name: string;
|
|
12
|
+
model_slug: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type OpenRouterModel = {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
created: number;
|
|
20
|
+
description: string;
|
|
21
|
+
context_length: number;
|
|
22
|
+
architecture: {
|
|
23
|
+
modality: string;
|
|
24
|
+
tokenizer: string;
|
|
25
|
+
instruct_type?: string;
|
|
26
|
+
};
|
|
27
|
+
top_provider: {
|
|
28
|
+
context_length: number;
|
|
29
|
+
/** `null` means it's the same as the context_length */
|
|
30
|
+
max_completion_tokens: number | null;
|
|
31
|
+
is_moderated: boolean;
|
|
32
|
+
};
|
|
33
|
+
pricing: {
|
|
34
|
+
prompt: string;
|
|
35
|
+
completion: string;
|
|
36
|
+
image: string;
|
|
37
|
+
request: string;
|
|
38
|
+
input_cache_read: string;
|
|
39
|
+
input_cache_write: string;
|
|
40
|
+
web_search: string;
|
|
41
|
+
internal_reasoning: string;
|
|
42
|
+
};
|
|
43
|
+
per_request_limits?: Record<string, unknown>;
|
|
44
|
+
};
|
|
45
|
+
declare function getOpenRouterModels(): Promise<OpenRouterModel[]>;
|
|
46
|
+
declare function getOpenRouterModelTokenLimits(modelId: string): Promise<{
|
|
47
|
+
contextLength: number;
|
|
48
|
+
maxCompletionTokens: number;
|
|
49
|
+
} | null>;
|
|
50
|
+
|
|
51
|
+
interface RetryOptions {
|
|
52
|
+
maxRetries: number;
|
|
53
|
+
onError?: (error: unknown) => Promise<void> | void;
|
|
54
|
+
/** Return `false` to stop retrying, `true` to automatically delay the next retry, or a number to set the delay before the next retry */
|
|
55
|
+
isErrorRetryable?: (error: unknown) => Promise<boolean | number> | boolean | number;
|
|
56
|
+
}
|
|
57
|
+
declare function retry<T>(fn: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
58
|
+
|
|
59
|
+
export { type OpenRouterError, type OpenRouterModel, getOpenRouterModelTokenLimits, getOpenRouterModels, retry };
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/helpers/index.ts
|
|
21
|
+
var helpers_exports = {};
|
|
22
|
+
__export(helpers_exports, {
|
|
23
|
+
getOpenRouterModelTokenLimits: () => getOpenRouterModelTokenLimits,
|
|
24
|
+
getOpenRouterModels: () => getOpenRouterModels,
|
|
25
|
+
retry: () => retry
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
28
|
+
|
|
29
|
+
// src/helpers/openrouter.ts
|
|
30
|
+
async function getOpenRouterModels() {
|
|
31
|
+
const response = await fetch("https://openrouter.ai/api/v1/models");
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error("Failed to fetch models");
|
|
34
|
+
}
|
|
35
|
+
const result = await response.json();
|
|
36
|
+
return result.data;
|
|
37
|
+
}
|
|
38
|
+
async function getOpenRouterModelTokenLimits(modelId) {
|
|
39
|
+
const models = await getOpenRouterModels();
|
|
40
|
+
const model = models.find((m) => m.id === modelId);
|
|
41
|
+
if (!model) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
contextLength: model.context_length,
|
|
46
|
+
maxCompletionTokens: model.top_provider.max_completion_tokens || model.context_length
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/helpers/retry.ts
|
|
51
|
+
function sleep(ms) {
|
|
52
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
53
|
+
}
|
|
54
|
+
async function retry(fn, options) {
|
|
55
|
+
let delay = 1e3;
|
|
56
|
+
let lastError = null;
|
|
57
|
+
for (let i = 0; i < options.maxRetries + 1; i++) {
|
|
58
|
+
try {
|
|
59
|
+
return await fn();
|
|
60
|
+
} catch (err) {
|
|
61
|
+
lastError = err;
|
|
62
|
+
if (options.onError) {
|
|
63
|
+
await options.onError(err);
|
|
64
|
+
}
|
|
65
|
+
let shouldRetry;
|
|
66
|
+
if (options.isErrorRetryable) {
|
|
67
|
+
shouldRetry = await options.isErrorRetryable(err);
|
|
68
|
+
}
|
|
69
|
+
if (shouldRetry === false) {
|
|
70
|
+
throw lastError;
|
|
71
|
+
} else if (typeof shouldRetry === "number" && Number.isFinite(shouldRetry)) {
|
|
72
|
+
await sleep(shouldRetry);
|
|
73
|
+
} else {
|
|
74
|
+
await sleep(delay);
|
|
75
|
+
delay *= 2;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw lastError;
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
getOpenRouterModelTokenLimits,
|
|
84
|
+
getOpenRouterModels,
|
|
85
|
+
retry
|
|
86
|
+
});
|
package/dist/helpers.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/helpers/openrouter.ts
|
|
2
|
+
async function getOpenRouterModels() {
|
|
3
|
+
const response = await fetch("https://openrouter.ai/api/v1/models");
|
|
4
|
+
if (!response.ok) {
|
|
5
|
+
throw new Error("Failed to fetch models");
|
|
6
|
+
}
|
|
7
|
+
const result = await response.json();
|
|
8
|
+
return result.data;
|
|
9
|
+
}
|
|
10
|
+
async function getOpenRouterModelTokenLimits(modelId) {
|
|
11
|
+
const models = await getOpenRouterModels();
|
|
12
|
+
const model = models.find((m) => m.id === modelId);
|
|
13
|
+
if (!model) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
contextLength: model.context_length,
|
|
18
|
+
maxCompletionTokens: model.top_provider.max_completion_tokens || model.context_length
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/helpers/retry.ts
|
|
23
|
+
function sleep(ms) {
|
|
24
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
25
|
+
}
|
|
26
|
+
async function retry(fn, options) {
|
|
27
|
+
let delay = 1e3;
|
|
28
|
+
let lastError = null;
|
|
29
|
+
for (let i = 0; i < options.maxRetries + 1; i++) {
|
|
30
|
+
try {
|
|
31
|
+
return await fn();
|
|
32
|
+
} catch (err) {
|
|
33
|
+
lastError = err;
|
|
34
|
+
if (options.onError) {
|
|
35
|
+
await options.onError(err);
|
|
36
|
+
}
|
|
37
|
+
let shouldRetry;
|
|
38
|
+
if (options.isErrorRetryable) {
|
|
39
|
+
shouldRetry = await options.isErrorRetryable(err);
|
|
40
|
+
}
|
|
41
|
+
if (shouldRetry === false) {
|
|
42
|
+
throw lastError;
|
|
43
|
+
} else if (typeof shouldRetry === "number" && Number.isFinite(shouldRetry)) {
|
|
44
|
+
await sleep(shouldRetry);
|
|
45
|
+
} else {
|
|
46
|
+
await sleep(delay);
|
|
47
|
+
delay *= 2;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throw lastError;
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
getOpenRouterModelTokenLimits,
|
|
55
|
+
getOpenRouterModels,
|
|
56
|
+
retry
|
|
57
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,20 @@ var PluginRuntimeInfo = class _PluginRuntimeInfo {
|
|
|
56
56
|
}
|
|
57
57
|
static getInstance(env) {
|
|
58
58
|
if (!_PluginRuntimeInfo._instance) {
|
|
59
|
-
|
|
59
|
+
switch ((0, import_adapter.getRuntimeKey)()) {
|
|
60
|
+
case "workerd":
|
|
61
|
+
_PluginRuntimeInfo._instance = new CfRuntimeInfo(env);
|
|
62
|
+
break;
|
|
63
|
+
case "deno":
|
|
64
|
+
_PluginRuntimeInfo._instance = new DenoRuntimeInfo(env);
|
|
65
|
+
break;
|
|
66
|
+
case "node":
|
|
67
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env);
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
60
73
|
}
|
|
61
74
|
return _PluginRuntimeInfo._instance;
|
|
62
75
|
}
|
|
@@ -82,6 +95,42 @@ var NodeRuntimeInfo = class extends PluginRuntimeInfo {
|
|
|
82
95
|
return import_github.default.context.payload.repository ? `${import_github.default.context.payload.repository?.html_url}/actions/runs/${import_github.default.context.runId}` : "http://localhost";
|
|
83
96
|
}
|
|
84
97
|
};
|
|
98
|
+
var DenoRuntimeInfo = class extends PluginRuntimeInfo {
|
|
99
|
+
get version() {
|
|
100
|
+
return Promise.resolve(Deno.env.get("DENO_DEPLOYMENT_ID"));
|
|
101
|
+
}
|
|
102
|
+
get runUrl() {
|
|
103
|
+
const projectName = Deno.env.get("DENO_PROJECT_NAME");
|
|
104
|
+
const baseUrl = `https://dash.deno.com/${projectName}/logs`;
|
|
105
|
+
const start = new Date(Date.now() - 6e4).toISOString();
|
|
106
|
+
const end = new Date(Date.now() + 6e4).toISOString();
|
|
107
|
+
const filters = {
|
|
108
|
+
query: "",
|
|
109
|
+
timeRangeOption: "custom",
|
|
110
|
+
recentValue: "1hour",
|
|
111
|
+
customValues: {
|
|
112
|
+
start,
|
|
113
|
+
end
|
|
114
|
+
},
|
|
115
|
+
logLevels: {
|
|
116
|
+
debug: true,
|
|
117
|
+
info: true,
|
|
118
|
+
warning: true,
|
|
119
|
+
error: true
|
|
120
|
+
},
|
|
121
|
+
regions: {
|
|
122
|
+
"gcp-asia-southeast1": true,
|
|
123
|
+
"gcp-europe-west2": true,
|
|
124
|
+
"gcp-europe-west3": true,
|
|
125
|
+
"gcp-southamerica-east1": true,
|
|
126
|
+
"gcp-us-east4": true,
|
|
127
|
+
"gcp-us-west2": true
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const filtersParam = encodeURIComponent(JSON.stringify(filters));
|
|
131
|
+
return `${baseUrl}?filters=${filtersParam}`;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
85
134
|
|
|
86
135
|
// src/util.ts
|
|
87
136
|
var import_ubiquity_os_logger = require("@ubiquity-os/ubiquity-os-logger");
|
package/dist/index.mjs
CHANGED
|
@@ -18,7 +18,20 @@ var PluginRuntimeInfo = class _PluginRuntimeInfo {
|
|
|
18
18
|
}
|
|
19
19
|
static getInstance(env) {
|
|
20
20
|
if (!_PluginRuntimeInfo._instance) {
|
|
21
|
-
|
|
21
|
+
switch (getRuntimeKey()) {
|
|
22
|
+
case "workerd":
|
|
23
|
+
_PluginRuntimeInfo._instance = new CfRuntimeInfo(env);
|
|
24
|
+
break;
|
|
25
|
+
case "deno":
|
|
26
|
+
_PluginRuntimeInfo._instance = new DenoRuntimeInfo(env);
|
|
27
|
+
break;
|
|
28
|
+
case "node":
|
|
29
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env);
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
_PluginRuntimeInfo._instance = new NodeRuntimeInfo(env);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
22
35
|
}
|
|
23
36
|
return _PluginRuntimeInfo._instance;
|
|
24
37
|
}
|
|
@@ -44,6 +57,42 @@ var NodeRuntimeInfo = class extends PluginRuntimeInfo {
|
|
|
44
57
|
return github.context.payload.repository ? `${github.context.payload.repository?.html_url}/actions/runs/${github.context.runId}` : "http://localhost";
|
|
45
58
|
}
|
|
46
59
|
};
|
|
60
|
+
var DenoRuntimeInfo = class extends PluginRuntimeInfo {
|
|
61
|
+
get version() {
|
|
62
|
+
return Promise.resolve(Deno.env.get("DENO_DEPLOYMENT_ID"));
|
|
63
|
+
}
|
|
64
|
+
get runUrl() {
|
|
65
|
+
const projectName = Deno.env.get("DENO_PROJECT_NAME");
|
|
66
|
+
const baseUrl = `https://dash.deno.com/${projectName}/logs`;
|
|
67
|
+
const start = new Date(Date.now() - 6e4).toISOString();
|
|
68
|
+
const end = new Date(Date.now() + 6e4).toISOString();
|
|
69
|
+
const filters = {
|
|
70
|
+
query: "",
|
|
71
|
+
timeRangeOption: "custom",
|
|
72
|
+
recentValue: "1hour",
|
|
73
|
+
customValues: {
|
|
74
|
+
start,
|
|
75
|
+
end
|
|
76
|
+
},
|
|
77
|
+
logLevels: {
|
|
78
|
+
debug: true,
|
|
79
|
+
info: true,
|
|
80
|
+
warning: true,
|
|
81
|
+
error: true
|
|
82
|
+
},
|
|
83
|
+
regions: {
|
|
84
|
+
"gcp-asia-southeast1": true,
|
|
85
|
+
"gcp-europe-west2": true,
|
|
86
|
+
"gcp-europe-west3": true,
|
|
87
|
+
"gcp-southamerica-east1": true,
|
|
88
|
+
"gcp-us-east4": true,
|
|
89
|
+
"gcp-us-west2": true
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const filtersParam = encodeURIComponent(JSON.stringify(filters));
|
|
93
|
+
return `${baseUrl}?filters=${filtersParam}`;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
47
96
|
|
|
48
97
|
// src/util.ts
|
|
49
98
|
import { LOG_LEVEL } from "@ubiquity-os/ubiquity-os-logger";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubiquity-os/plugin-sdk",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
4
4
|
"description": "SDK for plugin support.",
|
|
5
5
|
"author": "Ubiquity DAO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
],
|
|
25
25
|
"octokit": [
|
|
26
26
|
"dist/octokit.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"helpers": [
|
|
29
|
+
"dist/helpers.d.ts"
|
|
27
30
|
]
|
|
28
31
|
}
|
|
29
32
|
},
|
|
@@ -52,6 +55,11 @@
|
|
|
52
55
|
"types": "./dist/octokit.d.ts",
|
|
53
56
|
"import": "./dist/octokit.mjs",
|
|
54
57
|
"require": "./dist/octokit.js"
|
|
58
|
+
},
|
|
59
|
+
"./helpers": {
|
|
60
|
+
"types": "./dist/helpers.d.ts",
|
|
61
|
+
"import": "./dist/helpers.mjs",
|
|
62
|
+
"require": "./dist/helpers.js"
|
|
55
63
|
}
|
|
56
64
|
},
|
|
57
65
|
"files": [
|