@dungsil/dsh-plugin-cli-proxy-api 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/dist/index.js +51 -45
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1449,6 +1449,7 @@ function text(value, max = 1024) {
1449
1449
  }
1450
1450
  function apply(ctx, config) {
1451
1451
  let busy = false;
1452
+ let readers = 0;
1452
1453
  const sessions = /* @__PURE__ */ new Map();
1453
1454
  const lifetime = new AbortController();
1454
1455
  ctx.effect(() => () => lifetime.abort());
@@ -1798,53 +1799,58 @@ function apply(ctx, config) {
1798
1799
  "oauth-status",
1799
1800
  "oauth-cancel",
1800
1801
  "oauth-callback"
1801
- ]) ctx.effect(() => ctx.connection.fetch.register({
1802
- path: `${channel}/${endpointPrefix}${endpoint}`,
1803
- methods: ["POST"],
1804
- requestBody: "buffered",
1805
- async fetch(request) {
1806
- let body;
1807
- try {
1808
- body = clientRequestSchema.safeParse(await request.json());
1809
- } catch {
1810
- return new Response("Invalid request", { status: 400 });
1811
- }
1812
- if (!body.success || body.data.method !== `dungsil-cli-proxy-api/${endpoint}`) return new Response("Invalid request", { status: 400 });
1813
- let result;
1814
- if (busy) result = {
1815
- ok: false,
1816
- error: {
1817
- code: "busy",
1818
- message: "CLIProxyAPI operation in progress.",
1819
- details: {}
1820
- }
1821
- };
1822
- else {
1823
- busy = true;
1802
+ ]) {
1803
+ const readOnly = endpoint === "describe" || endpoint === "quota-list" || endpoint === "quota-fetch";
1804
+ ctx.effect(() => ctx.connection.fetch.register({
1805
+ path: `${channel}/${endpointPrefix}${endpoint}`,
1806
+ methods: ["POST"],
1807
+ requestBody: "buffered",
1808
+ async fetch(request) {
1809
+ let body;
1824
1810
  try {
1825
- result = {
1826
- ok: true,
1827
- value: await handle(endpoint, body.data.payload, request.signal)
1828
- };
1829
- } catch (error) {
1830
- result = {
1831
- ok: false,
1832
- error: {
1833
- code: error instanceof Error && errors.has(error.message) ? error.message : "operation_failed",
1834
- message: "CLIProxyAPI operation could not be confirmed.",
1835
- details: {}
1836
- }
1837
- };
1838
- } finally {
1839
- busy = false;
1811
+ body = clientRequestSchema.safeParse(await request.json());
1812
+ } catch {
1813
+ return new Response("Invalid request", { status: 400 });
1840
1814
  }
1815
+ if (!body.success || body.data.method !== `dungsil-cli-proxy-api/${endpoint}`) return new Response("Invalid request", { status: 400 });
1816
+ let result;
1817
+ if (busy || !readOnly && readers > 0) result = {
1818
+ ok: false,
1819
+ error: {
1820
+ code: "busy",
1821
+ message: "CLIProxyAPI operation in progress.",
1822
+ details: {}
1823
+ }
1824
+ };
1825
+ else {
1826
+ if (readOnly) readers++;
1827
+ else busy = true;
1828
+ try {
1829
+ result = {
1830
+ ok: true,
1831
+ value: await handle(endpoint, body.data.payload, request.signal)
1832
+ };
1833
+ } catch (error) {
1834
+ result = {
1835
+ ok: false,
1836
+ error: {
1837
+ code: error instanceof Error && errors.has(error.message) ? error.message : "operation_failed",
1838
+ message: "CLIProxyAPI operation could not be confirmed.",
1839
+ details: {}
1840
+ }
1841
+ };
1842
+ } finally {
1843
+ if (readOnly) readers--;
1844
+ else busy = false;
1845
+ }
1846
+ }
1847
+ return Response.json({
1848
+ type: "server-response",
1849
+ rpcId: body.data.rpcId,
1850
+ result
1851
+ }, { headers: { "Cache-Control": "no-store" } });
1841
1852
  }
1842
- return Response.json({
1843
- type: "server-response",
1844
- rpcId: body.data.rpcId,
1845
- result
1846
- }, { headers: { "Cache-Control": "no-store" } });
1847
- }
1848
- }), `cli-proxy-api: owner-only ${endpoint}`);
1853
+ }), `cli-proxy-api: owner-only ${endpoint}`);
1854
+ }
1849
1855
  }
1850
1856
  export { Config, apply, inject, name };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dungsil/dsh-plugin-cli-proxy-api",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "CLIProxyAPI model provider and owner-only management settings for DeepSeek Harness.",
5
5
  "license": "MIT",
6
6
  "repository": {