@omnicross/subscriptions 0.1.5 → 0.1.7

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/NOTICE CHANGED
@@ -1,41 +1,12 @@
1
1
  @omnicross/subscriptions — THIRD-PARTY NOTICES
2
2
  ==============================================
3
3
 
4
- This package contains the subscription-as-provider block (auth strategies,
5
- account service, provider registry, dispatcher, OpenCodeGo routing). Some routing
6
- shapes and configuration-data values were adapted,
7
- clean-room, from the following third-party works. Those repositories are NOT
8
- vendored into this tree; only original TypeScript that mirrors their routing
9
- shape / config-data values lives here (see the in-code provenance comments).
4
+ This package contains the subscription-as-provider block (auth strategies,
5
+ account service, provider registry, dispatcher, and OpenCodeGo routing) and uses
6
+ the following third-party dependency. Its license applies to that dependency.
10
7
 
11
8
  --------------------------------------------------------------------------------
12
- 1. claude-relay-service (MIT License) — routing shape only
13
- --------------------------------------------------------------------------------
14
-
15
- The Codex (ChatGPT OAuth) upstream routing shape — the
16
- `https://chatgpt.com/backend-api/codex/responses` endpoint dispatch in
17
- `src/SubscriptionProviderRegistry.ts` — mirrors the route shape of
18
- `claude-relay-service` (`src/routes/openaiRoutes.js`). Routing shape only; the
19
- TypeScript is original, and the upstream repository is not vendored.
20
-
21
- https://github.com/Wei-Shaw/claude-relay-service
22
- Licensed under the MIT License.
23
-
24
- --------------------------------------------------------------------------------
25
- 2. oc-go-cc (OpenCodeGo CC) — model-map + routing-shape / config-data
26
- --------------------------------------------------------------------------------
27
-
28
- The OpenCodeGo routing-shape, scenario router, model-map defaults, endpoint
29
- shapes, and Anthropic-shape `x-api-key` fallback in
30
- `src/opencodego/{defaults,endpoints,model-shape,ScenarioRouter}.ts` and
31
- `src/auth/StaticBearerAuthStrategy.ts` are clean-room ports of the model-map and
32
- routing shape from `oc-go-cc` (`internal/router/model_router.go`,
33
- `internal/client/opencode.go`, `configs/config.example.json`). Configuration
34
- data + routing shape only; the TypeScript is original, and the upstream
35
- repository is not vendored.
36
-
37
- --------------------------------------------------------------------------------
38
- 3. js-tiktoken (MIT License)
9
+ 1. js-tiktoken (MIT License)
39
10
  --------------------------------------------------------------------------------
40
11
 
41
12
  `src/opencodego/token-count.ts` lazily imports `js-tiktoken` (cl100k_base
@@ -29,39 +29,70 @@ function errorMessage(error, errorDescription) {
29
29
  }
30
30
  return String(error);
31
31
  }
32
- async function postForm(fetchImpl, url, params, parseErrorMessage) {
33
- const response = await fetchImpl(url, {
34
- method: "POST",
35
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
36
- body: params.toString()
37
- });
32
+ function withStatus(message, response) {
33
+ return response.ok ? message : `${message} (HTTP ${response.status})`;
34
+ }
35
+ var DEFAULT_TOKEN_TIMEOUT_MS = 3e4;
36
+ async function fetchWithTimeout(fetchImpl, url, init, timeoutMs) {
37
+ const controller = new AbortController();
38
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
39
+ try {
40
+ return await fetchImpl(url, { ...init, signal: controller.signal });
41
+ } catch (e) {
42
+ if (controller.signal.aborted) {
43
+ throw new Error(`token endpoint timed out after ${Math.round(timeoutMs / 1e3)}s`);
44
+ }
45
+ throw e;
46
+ } finally {
47
+ clearTimeout(timer);
48
+ }
49
+ }
50
+ async function postForm(fetchImpl, url, params, parseErrorMessage, timeoutMs = DEFAULT_TOKEN_TIMEOUT_MS) {
51
+ const response = await fetchWithTimeout(
52
+ fetchImpl,
53
+ url,
54
+ {
55
+ method: "POST",
56
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
57
+ body: params.toString()
58
+ },
59
+ timeoutMs
60
+ );
38
61
  const responseData = await response.text();
39
62
  let data;
40
63
  try {
41
64
  data = JSON.parse(responseData);
42
65
  } catch (e2) {
43
- throw new Error(parseErrorMessage);
66
+ throw new Error(withStatus(parseErrorMessage, response));
44
67
  }
45
68
  if (data.error) {
46
- throw new Error(errorMessage(data.error, data.error_description));
69
+ throw new Error(withStatus(errorMessage(data.error, data.error_description), response));
47
70
  }
48
71
  return data;
49
72
  }
50
- async function postJson(fetchImpl, url, body, parseErrorMessage, extraHeaders = {}) {
51
- const response = await fetchImpl(url, {
52
- method: "POST",
53
- headers: { "Content-Type": "application/json", ...extraHeaders },
54
- body: JSON.stringify(body)
55
- });
73
+ async function postJson(fetchImpl, url, body, parseErrorMessage, extraHeaders = {}, timeoutMs = DEFAULT_TOKEN_TIMEOUT_MS) {
74
+ const response = await fetchWithTimeout(
75
+ fetchImpl,
76
+ url,
77
+ {
78
+ method: "POST",
79
+ headers: { "Content-Type": "application/json", ...extraHeaders },
80
+ body: JSON.stringify(body)
81
+ },
82
+ timeoutMs
83
+ );
56
84
  const responseData = await response.text();
57
85
  let data;
58
86
  try {
59
87
  data = JSON.parse(responseData);
60
88
  } catch (e3) {
61
- throw new Error(parseErrorMessage);
89
+ throw new Error(withStatus(parseErrorMessage, response));
62
90
  }
63
91
  if (data.error) {
64
- throw new Error(errorMessage(data.error, data.error_description));
92
+ throw new Error(withStatus(errorMessage(data.error, data.error_description), response));
93
+ }
94
+ if (!response.ok) {
95
+ throw new Error(withStatus("token endpoint rejected the request", response));
65
96
  }
66
97
  return data;
67
98
  }
@@ -29,39 +29,70 @@ function errorMessage(error, errorDescription) {
29
29
  }
30
30
  return String(error);
31
31
  }
32
- async function postForm(fetchImpl, url, params, parseErrorMessage) {
33
- const response = await fetchImpl(url, {
34
- method: "POST",
35
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
36
- body: params.toString()
37
- });
32
+ function withStatus(message, response) {
33
+ return response.ok ? message : `${message} (HTTP ${response.status})`;
34
+ }
35
+ var DEFAULT_TOKEN_TIMEOUT_MS = 3e4;
36
+ async function fetchWithTimeout(fetchImpl, url, init, timeoutMs) {
37
+ const controller = new AbortController();
38
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
39
+ try {
40
+ return await fetchImpl(url, { ...init, signal: controller.signal });
41
+ } catch (e) {
42
+ if (controller.signal.aborted) {
43
+ throw new Error(`token endpoint timed out after ${Math.round(timeoutMs / 1e3)}s`);
44
+ }
45
+ throw e;
46
+ } finally {
47
+ clearTimeout(timer);
48
+ }
49
+ }
50
+ async function postForm(fetchImpl, url, params, parseErrorMessage, timeoutMs = DEFAULT_TOKEN_TIMEOUT_MS) {
51
+ const response = await fetchWithTimeout(
52
+ fetchImpl,
53
+ url,
54
+ {
55
+ method: "POST",
56
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
57
+ body: params.toString()
58
+ },
59
+ timeoutMs
60
+ );
38
61
  const responseData = await response.text();
39
62
  let data;
40
63
  try {
41
64
  data = JSON.parse(responseData);
42
65
  } catch {
43
- throw new Error(parseErrorMessage);
66
+ throw new Error(withStatus(parseErrorMessage, response));
44
67
  }
45
68
  if (data.error) {
46
- throw new Error(errorMessage(data.error, data.error_description));
69
+ throw new Error(withStatus(errorMessage(data.error, data.error_description), response));
47
70
  }
48
71
  return data;
49
72
  }
50
- async function postJson(fetchImpl, url, body, parseErrorMessage, extraHeaders = {}) {
51
- const response = await fetchImpl(url, {
52
- method: "POST",
53
- headers: { "Content-Type": "application/json", ...extraHeaders },
54
- body: JSON.stringify(body)
55
- });
73
+ async function postJson(fetchImpl, url, body, parseErrorMessage, extraHeaders = {}, timeoutMs = DEFAULT_TOKEN_TIMEOUT_MS) {
74
+ const response = await fetchWithTimeout(
75
+ fetchImpl,
76
+ url,
77
+ {
78
+ method: "POST",
79
+ headers: { "Content-Type": "application/json", ...extraHeaders },
80
+ body: JSON.stringify(body)
81
+ },
82
+ timeoutMs
83
+ );
56
84
  const responseData = await response.text();
57
85
  let data;
58
86
  try {
59
87
  data = JSON.parse(responseData);
60
88
  } catch {
61
- throw new Error(parseErrorMessage);
89
+ throw new Error(withStatus(parseErrorMessage, response));
62
90
  }
63
91
  if (data.error) {
64
- throw new Error(errorMessage(data.error, data.error_description));
92
+ throw new Error(withStatus(errorMessage(data.error, data.error_description), response));
93
+ }
94
+ if (!response.ok) {
95
+ throw new Error(withStatus("token endpoint rejected the request", response));
65
96
  }
66
97
  return data;
67
98
  }