@ubiquity-os/plugin-sdk 3.6.0 → 3.6.2

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/llm.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { ChatCompletionMessageParam, ChatCompletion, ChatCompletionChunk } from 'openai/resources/chat/completions';
2
1
  import { C as Context } from './context-sqbr2o6i.mjs';
2
+ import { PluginInput } from './signature.mjs';
3
+ import { ChatCompletionMessageParam, ChatCompletionCreateParamsNonStreaming, ChatCompletion, ChatCompletionChunk } from 'openai/resources/chat/completions';
3
4
  import '@octokit/webhooks';
4
5
  import '@ubiquity-os/ubiquity-os-logger';
5
6
  import '@octokit/plugin-rest-endpoint-methods';
@@ -7,54 +8,16 @@ import './octokit.mjs';
7
8
  import '@octokit/core/types';
8
9
  import '@octokit/plugin-paginate-graphql';
9
10
  import '@octokit/plugin-paginate-rest';
10
- import '@octokit/webhooks/node_modules/@octokit/request-error';
11
+ import '@octokit/request-error';
11
12
  import '@octokit/core';
13
+ import '@sinclair/typebox';
12
14
 
13
- type LlmResponseFormat = {
14
- type: "json_object" | "text";
15
- } | {
16
- type: string;
17
- [key: string]: unknown;
18
- };
19
- type LlmPayload = {
20
- repository?: {
21
- owner?: {
22
- login?: string;
23
- };
24
- name?: string;
25
- };
26
- installation?: {
27
- id?: number;
28
- };
29
- };
30
- type LlmAuthContext = {
31
- authToken?: string;
32
- ubiquityKernelToken?: string;
33
- payload?: LlmPayload;
34
- eventPayload?: LlmPayload;
35
- };
36
15
  type LlmCallOptions = {
37
16
  baseUrl?: string;
38
17
  model?: string;
39
18
  stream?: boolean;
40
19
  messages: ChatCompletionMessageParam[];
41
- max_tokens?: number;
42
- max_completion_tokens?: number;
43
- temperature?: number;
44
- top_p?: number;
45
- frequency_penalty?: number;
46
- presence_penalty?: number;
47
- response_format?: LlmResponseFormat;
48
- stop?: string | string[];
49
- n?: number;
50
- logit_bias?: Record<string, number>;
51
- seed?: number;
52
- user?: string;
53
- metadata?: Record<string, unknown>;
54
- tools?: unknown[];
55
- tool_choice?: string | Record<string, unknown>;
56
- [key: string]: unknown;
57
- };
58
- declare function callLlm(options: LlmCallOptions, input: Context | LlmAuthContext): Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>>;
20
+ } & Partial<Omit<ChatCompletionCreateParamsNonStreaming, "model" | "messages" | "stream">>;
21
+ declare function callLlm(options: LlmCallOptions, input: PluginInput | Context): Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>>;
59
22
 
60
23
  export { type LlmCallOptions, callLlm };
package/dist/llm.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { ChatCompletionMessageParam, ChatCompletion, ChatCompletionChunk } from 'openai/resources/chat/completions';
2
1
  import { C as Context } from './context-BbEmsEct.js';
2
+ import { PluginInput } from './signature.js';
3
+ import { ChatCompletionMessageParam, ChatCompletionCreateParamsNonStreaming, ChatCompletion, ChatCompletionChunk } from 'openai/resources/chat/completions';
3
4
  import '@octokit/webhooks';
4
5
  import '@ubiquity-os/ubiquity-os-logger';
5
6
  import '@octokit/plugin-rest-endpoint-methods';
@@ -7,54 +8,16 @@ import './octokit.js';
7
8
  import '@octokit/core/types';
8
9
  import '@octokit/plugin-paginate-graphql';
9
10
  import '@octokit/plugin-paginate-rest';
10
- import '@octokit/webhooks/node_modules/@octokit/request-error';
11
+ import '@octokit/request-error';
11
12
  import '@octokit/core';
13
+ import '@sinclair/typebox';
12
14
 
13
- type LlmResponseFormat = {
14
- type: "json_object" | "text";
15
- } | {
16
- type: string;
17
- [key: string]: unknown;
18
- };
19
- type LlmPayload = {
20
- repository?: {
21
- owner?: {
22
- login?: string;
23
- };
24
- name?: string;
25
- };
26
- installation?: {
27
- id?: number;
28
- };
29
- };
30
- type LlmAuthContext = {
31
- authToken?: string;
32
- ubiquityKernelToken?: string;
33
- payload?: LlmPayload;
34
- eventPayload?: LlmPayload;
35
- };
36
15
  type LlmCallOptions = {
37
16
  baseUrl?: string;
38
17
  model?: string;
39
18
  stream?: boolean;
40
19
  messages: ChatCompletionMessageParam[];
41
- max_tokens?: number;
42
- max_completion_tokens?: number;
43
- temperature?: number;
44
- top_p?: number;
45
- frequency_penalty?: number;
46
- presence_penalty?: number;
47
- response_format?: LlmResponseFormat;
48
- stop?: string | string[];
49
- n?: number;
50
- logit_bias?: Record<string, number>;
51
- seed?: number;
52
- user?: string;
53
- metadata?: Record<string, unknown>;
54
- tools?: unknown[];
55
- tool_choice?: string | Record<string, unknown>;
56
- [key: string]: unknown;
57
- };
58
- declare function callLlm(options: LlmCallOptions, input: Context | LlmAuthContext): Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>>;
20
+ } & Partial<Omit<ChatCompletionCreateParamsNonStreaming, "model" | "messages" | "stream">>;
21
+ declare function callLlm(options: LlmCallOptions, input: PluginInput | Context): Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>>;
59
22
 
60
23
  export { type LlmCallOptions, callLlm };
package/dist/llm.js CHANGED
@@ -24,11 +24,7 @@ __export(llm_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(llm_exports);
26
26
  function normalizeBaseUrl(baseUrl) {
27
- let normalized = baseUrl.trim();
28
- while (normalized.endsWith("/")) {
29
- normalized = normalized.slice(0, -1);
30
- }
31
- return normalized;
27
+ return baseUrl.trim().replace(/\/+$/, "");
32
28
  }
33
29
  function getEnvString(name) {
34
30
  if (typeof process === "undefined" || !process?.env) return "";
@@ -43,25 +39,24 @@ function getAiBaseUrl(options) {
43
39
  return "https://ai.ubq.fi";
44
40
  }
45
41
  async function callLlm(options, input) {
46
- const inputPayload = input;
47
- const authToken = inputPayload.authToken;
48
- const ubiquityKernelToken = inputPayload.ubiquityKernelToken;
49
- const payload = inputPayload.payload ?? inputPayload.eventPayload;
42
+ const authToken = input?.authToken ?? "";
43
+ const ubiquityKernelToken = input?.ubiquityKernelToken ?? "";
44
+ const payload = input?.payload;
50
45
  const owner = payload?.repository?.owner?.login ?? "";
51
46
  const repo = payload?.repository?.name ?? "";
52
47
  const installationId = payload?.installation?.id;
53
48
  if (!authToken) throw new Error("Missing authToken in inputs");
54
- const isKernelTokenRequired = authToken.trim().startsWith("gh");
55
- if (isKernelTokenRequired && !ubiquityKernelToken) {
49
+ const requiresKernelToken = authToken.trim().startsWith("gh");
50
+ if (requiresKernelToken && !ubiquityKernelToken) {
56
51
  throw new Error("Missing ubiquityKernelToken in inputs (kernel attestation is required for GitHub auth)");
57
52
  }
58
- const { baseUrl, model, stream: isStream, messages, ...rest } = options;
59
- const url = `${getAiBaseUrl({ ...options, baseUrl })}/v1/chat/completions`;
53
+ const url = `${getAiBaseUrl(options)}/v1/chat/completions`;
54
+ const { baseUrl: _baseUrl, model, stream, messages, ...rest } = options;
60
55
  const body = JSON.stringify({
61
56
  ...rest,
62
57
  ...model ? { model } : {},
63
58
  messages,
64
- stream: isStream ?? false
59
+ stream: stream ?? false
65
60
  });
66
61
  const headers = {
67
62
  Authorization: `Bearer ${authToken}`,
@@ -80,10 +75,7 @@ async function callLlm(options, input) {
80
75
  const err = await response.text();
81
76
  throw new Error(`LLM API error: ${response.status} - ${err}`);
82
77
  }
83
- if (isStream) {
84
- if (!response.body) {
85
- throw new Error("LLM API error: missing response body for streaming request");
86
- }
78
+ if (options.stream) {
87
79
  return parseSseStream(response.body);
88
80
  }
89
81
  return response.json();
@@ -94,8 +86,8 @@ async function* parseSseStream(body) {
94
86
  let buffer = "";
95
87
  try {
96
88
  while (true) {
97
- const { value, done: isDone } = await reader.read();
98
- if (isDone) break;
89
+ const { value, done } = await reader.read();
90
+ if (done) break;
99
91
  buffer += decoder.decode(value, { stream: true });
100
92
  const events = buffer.split("\n\n");
101
93
  buffer = events.pop() || "";
package/dist/llm.mjs CHANGED
@@ -1,10 +1,6 @@
1
1
  // src/llm/index.ts
2
2
  function normalizeBaseUrl(baseUrl) {
3
- let normalized = baseUrl.trim();
4
- while (normalized.endsWith("/")) {
5
- normalized = normalized.slice(0, -1);
6
- }
7
- return normalized;
3
+ return baseUrl.trim().replace(/\/+$/, "");
8
4
  }
9
5
  function getEnvString(name) {
10
6
  if (typeof process === "undefined" || !process?.env) return "";
@@ -19,25 +15,24 @@ function getAiBaseUrl(options) {
19
15
  return "https://ai.ubq.fi";
20
16
  }
21
17
  async function callLlm(options, input) {
22
- const inputPayload = input;
23
- const authToken = inputPayload.authToken;
24
- const ubiquityKernelToken = inputPayload.ubiquityKernelToken;
25
- const payload = inputPayload.payload ?? inputPayload.eventPayload;
18
+ const authToken = input?.authToken ?? "";
19
+ const ubiquityKernelToken = input?.ubiquityKernelToken ?? "";
20
+ const payload = input?.payload;
26
21
  const owner = payload?.repository?.owner?.login ?? "";
27
22
  const repo = payload?.repository?.name ?? "";
28
23
  const installationId = payload?.installation?.id;
29
24
  if (!authToken) throw new Error("Missing authToken in inputs");
30
- const isKernelTokenRequired = authToken.trim().startsWith("gh");
31
- if (isKernelTokenRequired && !ubiquityKernelToken) {
25
+ const requiresKernelToken = authToken.trim().startsWith("gh");
26
+ if (requiresKernelToken && !ubiquityKernelToken) {
32
27
  throw new Error("Missing ubiquityKernelToken in inputs (kernel attestation is required for GitHub auth)");
33
28
  }
34
- const { baseUrl, model, stream: isStream, messages, ...rest } = options;
35
- const url = `${getAiBaseUrl({ ...options, baseUrl })}/v1/chat/completions`;
29
+ const url = `${getAiBaseUrl(options)}/v1/chat/completions`;
30
+ const { baseUrl: _baseUrl, model, stream, messages, ...rest } = options;
36
31
  const body = JSON.stringify({
37
32
  ...rest,
38
33
  ...model ? { model } : {},
39
34
  messages,
40
- stream: isStream ?? false
35
+ stream: stream ?? false
41
36
  });
42
37
  const headers = {
43
38
  Authorization: `Bearer ${authToken}`,
@@ -56,10 +51,7 @@ async function callLlm(options, input) {
56
51
  const err = await response.text();
57
52
  throw new Error(`LLM API error: ${response.status} - ${err}`);
58
53
  }
59
- if (isStream) {
60
- if (!response.body) {
61
- throw new Error("LLM API error: missing response body for streaming request");
62
- }
54
+ if (options.stream) {
63
55
  return parseSseStream(response.body);
64
56
  }
65
57
  return response.json();
@@ -70,8 +62,8 @@ async function* parseSseStream(body) {
70
62
  let buffer = "";
71
63
  try {
72
64
  while (true) {
73
- const { value, done: isDone } = await reader.read();
74
- if (isDone) break;
65
+ const { value, done } = await reader.read();
66
+ if (done) break;
75
67
  buffer += decoder.decode(value, { stream: true });
76
68
  const events = buffer.split("\n\n");
77
69
  buffer = events.pop() || "";
@@ -3,12 +3,12 @@ import * as _octokit_plugin_paginate_graphql from '@octokit/plugin-paginate-grap
3
3
  import * as _octokit_plugin_rest_endpoint_methods from '@octokit/plugin-rest-endpoint-methods';
4
4
  export { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
5
5
  import * as _octokit_plugin_paginate_rest from '@octokit/plugin-paginate-rest';
6
- import * as _octokit_webhooks_node_modules__octokit_request_error from '@octokit/webhooks/node_modules/@octokit/request-error';
6
+ import * as _octokit_request_error from '@octokit/request-error';
7
7
  import { Octokit } from '@octokit/core';
8
8
 
9
9
  declare const customOctokit: typeof Octokit & _octokit_core_types.Constructor<{
10
10
  retry: {
11
- retryRequest: (error: _octokit_webhooks_node_modules__octokit_request_error.RequestError, retries: number, retryAfter: number) => _octokit_webhooks_node_modules__octokit_request_error.RequestError;
11
+ retryRequest: (error: _octokit_request_error.RequestError, retries: number, retryAfter: number) => _octokit_request_error.RequestError;
12
12
  };
13
13
  } & {
14
14
  paginate: _octokit_plugin_paginate_rest.PaginateInterface;
package/dist/octokit.d.ts CHANGED
@@ -3,12 +3,12 @@ import * as _octokit_plugin_paginate_graphql from '@octokit/plugin-paginate-grap
3
3
  import * as _octokit_plugin_rest_endpoint_methods from '@octokit/plugin-rest-endpoint-methods';
4
4
  export { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
5
5
  import * as _octokit_plugin_paginate_rest from '@octokit/plugin-paginate-rest';
6
- import * as _octokit_webhooks_node_modules__octokit_request_error from '@octokit/webhooks/node_modules/@octokit/request-error';
6
+ import * as _octokit_request_error from '@octokit/request-error';
7
7
  import { Octokit } from '@octokit/core';
8
8
 
9
9
  declare const customOctokit: typeof Octokit & _octokit_core_types.Constructor<{
10
10
  retry: {
11
- retryRequest: (error: _octokit_webhooks_node_modules__octokit_request_error.RequestError, retries: number, retryAfter: number) => _octokit_webhooks_node_modules__octokit_request_error.RequestError;
11
+ retryRequest: (error: _octokit_request_error.RequestError, retries: number, retryAfter: number) => _octokit_request_error.RequestError;
12
12
  };
13
13
  } & {
14
14
  paginate: _octokit_plugin_paginate_rest.PaginateInterface;
package/dist/octokit.js CHANGED
@@ -24,7 +24,169 @@ __export(octokit_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(octokit_exports);
26
26
  var import_core = require("@octokit/core");
27
- var import_plugin_paginate_graphql = require("@octokit/plugin-paginate-graphql");
27
+
28
+ // ../../node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js
29
+ var generateMessage = (path, cursorValue) => `The cursor at "${path.join(
30
+ ","
31
+ )}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
32
+ var MissingCursorChange = class extends Error {
33
+ constructor(pageInfo, cursorValue) {
34
+ super(generateMessage(pageInfo.pathInQuery, cursorValue));
35
+ this.pageInfo = pageInfo;
36
+ this.cursorValue = cursorValue;
37
+ if (Error.captureStackTrace) {
38
+ Error.captureStackTrace(this, this.constructor);
39
+ }
40
+ }
41
+ name = "MissingCursorChangeError";
42
+ };
43
+ var MissingPageInfo = class extends Error {
44
+ constructor(response) {
45
+ super(
46
+ `No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(
47
+ response,
48
+ null,
49
+ 2
50
+ )}`
51
+ );
52
+ this.response = response;
53
+ if (Error.captureStackTrace) {
54
+ Error.captureStackTrace(this, this.constructor);
55
+ }
56
+ }
57
+ name = "MissingPageInfo";
58
+ };
59
+ var isObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
60
+ function findPaginatedResourcePath(responseData) {
61
+ const paginatedResourcePath = deepFindPathToProperty(
62
+ responseData,
63
+ "pageInfo"
64
+ );
65
+ if (paginatedResourcePath.length === 0) {
66
+ throw new MissingPageInfo(responseData);
67
+ }
68
+ return paginatedResourcePath;
69
+ }
70
+ var deepFindPathToProperty = (object, searchProp, path = []) => {
71
+ for (const key of Object.keys(object)) {
72
+ const currentPath = [...path, key];
73
+ const currentValue = object[key];
74
+ if (isObject(currentValue)) {
75
+ if (currentValue.hasOwnProperty(searchProp)) {
76
+ return currentPath;
77
+ }
78
+ const result = deepFindPathToProperty(
79
+ currentValue,
80
+ searchProp,
81
+ currentPath
82
+ );
83
+ if (result.length > 0) {
84
+ return result;
85
+ }
86
+ }
87
+ }
88
+ return [];
89
+ };
90
+ var get = (object, path) => {
91
+ return path.reduce((current, nextProperty) => current[nextProperty], object);
92
+ };
93
+ var set = (object, path, mutator) => {
94
+ const lastProperty = path[path.length - 1];
95
+ const parentPath = [...path].slice(0, -1);
96
+ const parent = get(object, parentPath);
97
+ if (typeof mutator === "function") {
98
+ parent[lastProperty] = mutator(parent[lastProperty]);
99
+ } else {
100
+ parent[lastProperty] = mutator;
101
+ }
102
+ };
103
+ var extractPageInfos = (responseData) => {
104
+ const pageInfoPath = findPaginatedResourcePath(responseData);
105
+ return {
106
+ pathInQuery: pageInfoPath,
107
+ pageInfo: get(responseData, [...pageInfoPath, "pageInfo"])
108
+ };
109
+ };
110
+ var isForwardSearch = (givenPageInfo) => {
111
+ return givenPageInfo.hasOwnProperty("hasNextPage");
112
+ };
113
+ var getCursorFrom = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
114
+ var hasAnotherPage = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
115
+ var createIterator = (octokit) => {
116
+ return (query, initialParameters = {}) => {
117
+ let nextPageExists = true;
118
+ let parameters = { ...initialParameters };
119
+ return {
120
+ [Symbol.asyncIterator]: () => ({
121
+ async next() {
122
+ if (!nextPageExists) return { done: true, value: {} };
123
+ const response = await octokit.graphql(
124
+ query,
125
+ parameters
126
+ );
127
+ const pageInfoContext = extractPageInfos(response);
128
+ const nextCursorValue = getCursorFrom(pageInfoContext.pageInfo);
129
+ nextPageExists = hasAnotherPage(pageInfoContext.pageInfo);
130
+ if (nextPageExists && nextCursorValue === parameters.cursor) {
131
+ throw new MissingCursorChange(pageInfoContext, nextCursorValue);
132
+ }
133
+ parameters = {
134
+ ...parameters,
135
+ cursor: nextCursorValue
136
+ };
137
+ return { done: false, value: response };
138
+ }
139
+ })
140
+ };
141
+ };
142
+ };
143
+ var mergeResponses = (response1, response2) => {
144
+ if (Object.keys(response1).length === 0) {
145
+ return Object.assign(response1, response2);
146
+ }
147
+ const path = findPaginatedResourcePath(response1);
148
+ const nodesPath = [...path, "nodes"];
149
+ const newNodes = get(response2, nodesPath);
150
+ if (newNodes) {
151
+ set(response1, nodesPath, (values) => {
152
+ return [...values, ...newNodes];
153
+ });
154
+ }
155
+ const edgesPath = [...path, "edges"];
156
+ const newEdges = get(response2, edgesPath);
157
+ if (newEdges) {
158
+ set(response1, edgesPath, (values) => {
159
+ return [...values, ...newEdges];
160
+ });
161
+ }
162
+ const pageInfoPath = [...path, "pageInfo"];
163
+ set(response1, pageInfoPath, get(response2, pageInfoPath));
164
+ return response1;
165
+ };
166
+ var createPaginate = (octokit) => {
167
+ const iterator = createIterator(octokit);
168
+ return async (query, initialParameters = {}) => {
169
+ let mergedResponse = {};
170
+ for await (const response of iterator(
171
+ query,
172
+ initialParameters
173
+ )) {
174
+ mergedResponse = mergeResponses(mergedResponse, response);
175
+ }
176
+ return mergedResponse;
177
+ };
178
+ };
179
+ function paginateGraphQL(octokit) {
180
+ return {
181
+ graphql: Object.assign(octokit.graphql, {
182
+ paginate: Object.assign(createPaginate(octokit), {
183
+ iterator: createIterator(octokit)
184
+ })
185
+ })
186
+ };
187
+ }
188
+
189
+ // src/octokit.ts
28
190
  var import_plugin_paginate_rest = require("@octokit/plugin-paginate-rest");
29
191
  var import_plugin_rest_endpoint_methods = require("@octokit/plugin-rest-endpoint-methods");
30
192
  var import_plugin_retry = require("@octokit/plugin-retry");
@@ -45,7 +207,7 @@ var defaultOptions = {
45
207
  }
46
208
  }
47
209
  };
48
- var customOctokit = import_core.Octokit.plugin(import_plugin_throttling.throttling, import_plugin_retry.retry, import_plugin_paginate_rest.paginateRest, import_plugin_rest_endpoint_methods.restEndpointMethods, import_plugin_paginate_graphql.paginateGraphQL).defaults((instanceOptions) => {
210
+ var customOctokit = import_core.Octokit.plugin(import_plugin_throttling.throttling, import_plugin_retry.retry, import_plugin_paginate_rest.paginateRest, import_plugin_rest_endpoint_methods.restEndpointMethods, paginateGraphQL).defaults((instanceOptions) => {
49
211
  return { ...defaultOptions, ...instanceOptions };
50
212
  });
51
213
  // Annotate the CommonJS export names for ESM import in node:
package/dist/octokit.mjs CHANGED
@@ -1,6 +1,168 @@
1
1
  // src/octokit.ts
2
2
  import { Octokit } from "@octokit/core";
3
- import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
3
+
4
+ // ../../node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js
5
+ var generateMessage = (path, cursorValue) => `The cursor at "${path.join(
6
+ ","
7
+ )}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
8
+ var MissingCursorChange = class extends Error {
9
+ constructor(pageInfo, cursorValue) {
10
+ super(generateMessage(pageInfo.pathInQuery, cursorValue));
11
+ this.pageInfo = pageInfo;
12
+ this.cursorValue = cursorValue;
13
+ if (Error.captureStackTrace) {
14
+ Error.captureStackTrace(this, this.constructor);
15
+ }
16
+ }
17
+ name = "MissingCursorChangeError";
18
+ };
19
+ var MissingPageInfo = class extends Error {
20
+ constructor(response) {
21
+ super(
22
+ `No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(
23
+ response,
24
+ null,
25
+ 2
26
+ )}`
27
+ );
28
+ this.response = response;
29
+ if (Error.captureStackTrace) {
30
+ Error.captureStackTrace(this, this.constructor);
31
+ }
32
+ }
33
+ name = "MissingPageInfo";
34
+ };
35
+ var isObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
36
+ function findPaginatedResourcePath(responseData) {
37
+ const paginatedResourcePath = deepFindPathToProperty(
38
+ responseData,
39
+ "pageInfo"
40
+ );
41
+ if (paginatedResourcePath.length === 0) {
42
+ throw new MissingPageInfo(responseData);
43
+ }
44
+ return paginatedResourcePath;
45
+ }
46
+ var deepFindPathToProperty = (object, searchProp, path = []) => {
47
+ for (const key of Object.keys(object)) {
48
+ const currentPath = [...path, key];
49
+ const currentValue = object[key];
50
+ if (isObject(currentValue)) {
51
+ if (currentValue.hasOwnProperty(searchProp)) {
52
+ return currentPath;
53
+ }
54
+ const result = deepFindPathToProperty(
55
+ currentValue,
56
+ searchProp,
57
+ currentPath
58
+ );
59
+ if (result.length > 0) {
60
+ return result;
61
+ }
62
+ }
63
+ }
64
+ return [];
65
+ };
66
+ var get = (object, path) => {
67
+ return path.reduce((current, nextProperty) => current[nextProperty], object);
68
+ };
69
+ var set = (object, path, mutator) => {
70
+ const lastProperty = path[path.length - 1];
71
+ const parentPath = [...path].slice(0, -1);
72
+ const parent = get(object, parentPath);
73
+ if (typeof mutator === "function") {
74
+ parent[lastProperty] = mutator(parent[lastProperty]);
75
+ } else {
76
+ parent[lastProperty] = mutator;
77
+ }
78
+ };
79
+ var extractPageInfos = (responseData) => {
80
+ const pageInfoPath = findPaginatedResourcePath(responseData);
81
+ return {
82
+ pathInQuery: pageInfoPath,
83
+ pageInfo: get(responseData, [...pageInfoPath, "pageInfo"])
84
+ };
85
+ };
86
+ var isForwardSearch = (givenPageInfo) => {
87
+ return givenPageInfo.hasOwnProperty("hasNextPage");
88
+ };
89
+ var getCursorFrom = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
90
+ var hasAnotherPage = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
91
+ var createIterator = (octokit) => {
92
+ return (query, initialParameters = {}) => {
93
+ let nextPageExists = true;
94
+ let parameters = { ...initialParameters };
95
+ return {
96
+ [Symbol.asyncIterator]: () => ({
97
+ async next() {
98
+ if (!nextPageExists) return { done: true, value: {} };
99
+ const response = await octokit.graphql(
100
+ query,
101
+ parameters
102
+ );
103
+ const pageInfoContext = extractPageInfos(response);
104
+ const nextCursorValue = getCursorFrom(pageInfoContext.pageInfo);
105
+ nextPageExists = hasAnotherPage(pageInfoContext.pageInfo);
106
+ if (nextPageExists && nextCursorValue === parameters.cursor) {
107
+ throw new MissingCursorChange(pageInfoContext, nextCursorValue);
108
+ }
109
+ parameters = {
110
+ ...parameters,
111
+ cursor: nextCursorValue
112
+ };
113
+ return { done: false, value: response };
114
+ }
115
+ })
116
+ };
117
+ };
118
+ };
119
+ var mergeResponses = (response1, response2) => {
120
+ if (Object.keys(response1).length === 0) {
121
+ return Object.assign(response1, response2);
122
+ }
123
+ const path = findPaginatedResourcePath(response1);
124
+ const nodesPath = [...path, "nodes"];
125
+ const newNodes = get(response2, nodesPath);
126
+ if (newNodes) {
127
+ set(response1, nodesPath, (values) => {
128
+ return [...values, ...newNodes];
129
+ });
130
+ }
131
+ const edgesPath = [...path, "edges"];
132
+ const newEdges = get(response2, edgesPath);
133
+ if (newEdges) {
134
+ set(response1, edgesPath, (values) => {
135
+ return [...values, ...newEdges];
136
+ });
137
+ }
138
+ const pageInfoPath = [...path, "pageInfo"];
139
+ set(response1, pageInfoPath, get(response2, pageInfoPath));
140
+ return response1;
141
+ };
142
+ var createPaginate = (octokit) => {
143
+ const iterator = createIterator(octokit);
144
+ return async (query, initialParameters = {}) => {
145
+ let mergedResponse = {};
146
+ for await (const response of iterator(
147
+ query,
148
+ initialParameters
149
+ )) {
150
+ mergedResponse = mergeResponses(mergedResponse, response);
151
+ }
152
+ return mergedResponse;
153
+ };
154
+ };
155
+ function paginateGraphQL(octokit) {
156
+ return {
157
+ graphql: Object.assign(octokit.graphql, {
158
+ paginate: Object.assign(createPaginate(octokit), {
159
+ iterator: createIterator(octokit)
160
+ })
161
+ })
162
+ };
163
+ }
164
+
165
+ // src/octokit.ts
4
166
  import { paginateRest } from "@octokit/plugin-paginate-rest";
5
167
  import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
6
168
  import { retry } from "@octokit/plugin-retry";
@@ -15,10 +15,9 @@ declare class PluginInput<T extends EmitterWebhookEventName = EmitterWebhookEven
15
15
  eventPayload: EmitterWebhookEvent<T>["payload"];
16
16
  settings: unknown;
17
17
  authToken: string;
18
- ubiquityKernelToken?: string;
19
18
  ref: string;
20
19
  command: CommandCall;
21
- constructor(privateKey: string, stateId: string, eventName: T, eventPayload: EmitterWebhookEvent<T>["payload"], settings: unknown, authToken: string, ref: string, command: CommandCall, ubiquityKernelToken?: string);
20
+ constructor(privateKey: string, stateId: string, eventName: T, eventPayload: EmitterWebhookEvent<T>["payload"], settings: unknown, authToken: string, ref: string, command: CommandCall);
22
21
  getInputs(): Promise<{
23
22
  signature: string;
24
23
  stateId: string;
@@ -26,7 +25,6 @@ declare class PluginInput<T extends EmitterWebhookEventName = EmitterWebhookEven
26
25
  eventPayload: string;
27
26
  settings: string;
28
27
  authToken: string;
29
- ubiquityKernelToken: string | undefined;
30
28
  ref: string;
31
29
  command: string;
32
30
  }>;