@kosuke-ai/kosuke 1.0.98 → 1.0.100

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.100
4
+
5
+ - When an integration tool call is rate limited, `kosuke integrations tools call` now says how many seconds to wait before trying again.
6
+
7
+ ## 1.0.99
8
+
9
+ - `integrations request` and `integrations list --toolkit` take a toolkit slug in any case, such as `SLACK`.
10
+
3
11
  ## 1.0.98
4
12
 
5
13
  - `integrations list` help now says the Personal space is a workspace with workspace connections of its own, and that scope personal is your own account, reached in every workspace.
@@ -8,7 +8,7 @@ import { isTurnToken } from '../runtime/credentials.js';
8
8
  * 60 s budget, and wait no longer than their answer takes.
9
9
  */
10
10
  export const CALL_TIMEOUT_MS = 330_000;
11
- const TOOLKIT_PATTERN = /^[a-z0-9_]{1,64}$/;
11
+ const TOOLKIT_PATTERN = /^[a-z0-9_]{1,64}$/i;
12
12
  const MAX_ACCOUNT_CHARS = 100;
13
13
  /** The header a call made by a Delegated Run carries, so the platform counts it as a delegate's. */
14
14
  export const DELEGATED_RUN_HEADER = 'x-kosuke-delegated-run';
@@ -24,7 +24,8 @@ export function toolkitSlug(raw) {
24
24
  if (!TOOLKIT_PATTERN.test(raw)) {
25
25
  throw new InvalidArgumentError('Expected a toolkit slug such as gmail, as `list` prints it.');
26
26
  }
27
- return raw;
27
+ // Slugs are lower case; `SLACK` names the same toolkit, as `SLACK_SEND_MESSAGE` names its tool.
28
+ return raw.toLowerCase();
28
29
  }
29
30
  export function accountText(raw) {
30
31
  // A flag swallowed as the value (`--account --args`) shows as a leading dash.
@@ -85,6 +85,22 @@ function sentenceOf(error, status) {
85
85
  const said = isRow(error) ? oneLine(error.error, 300) : '';
86
86
  return said || `HTTP ${status}`;
87
87
  }
88
+ /** Seconds the platform asked to wait on a 429, bounded to the minute its budgets run on. */
89
+ function retryAfterOf(error) {
90
+ const value = isRow(error) ? error.retryAfterSeconds : undefined;
91
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 1)
92
+ return null;
93
+ return Math.min(60, Math.ceil(value));
94
+ }
95
+ /** A 429's sentence: the platform's own, else ours, always ending in how long to wait. */
96
+ function tooManyMessage(error) {
97
+ const seconds = retryAfterOf(error);
98
+ if (seconds === null)
99
+ return 'Too many requests. Try again shortly.';
100
+ const said = isRow(error) ? oneLine(error.error, 300).replace(/\s*Try again\b.*$/, '') : '';
101
+ const wait = `Wait ${seconds} second${seconds === 1 ? '' : 's'} before trying again.`;
102
+ return said ? `${said} ${wait}` : `Too many requests. ${wait}`;
103
+ }
88
104
  /**
89
105
  * Why a request failed, in words the reader can act on. The 4xx sentences are
90
106
  * the platform's own (a Connector Token, a workspace the key is not a member of,
@@ -103,7 +119,7 @@ export function failureOf(status, error, method) {
103
119
  };
104
120
  }
105
121
  if (status === 429) {
106
- return { ok: false, status, message: 'Too many requests. Try again shortly.' };
122
+ return { ok: false, status, message: tooManyMessage(error) };
107
123
  }
108
124
  if (status >= 400 && status < 500) {
109
125
  return { ok: false, status, message: sentenceOf(error, status) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosuke-ai/kosuke",
3
- "version": "1.0.98",
3
+ "version": "1.0.100",
4
4
  "description": "Sensei platform CLI. The client customers install to drive app.kosuke.ai from their own machine.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -43,10 +43,10 @@
43
43
  "minimatch": "^11.0.1"
44
44
  },
45
45
  "kosukeRelease": {
46
- "sourceCommit": "b3e04b750a9588604eee110b274ae6bc537eaf17",
47
- "sourceIdentity": "850c5ee3c5dcacc778367ae61fa40f309c9cf296be3ebfd3fb0569f9de77ca10",
46
+ "sourceCommit": "3c780f8681d98f9a28af2ba6d9ab02461fd53228",
47
+ "sourceIdentity": "bf0207239e671e75c5d6a2a0270a0f4dfbf78a7deb24348c850133c6a10d3d69",
48
48
  "fragments": [
49
- "integrations-personal-space-help-p3k9dw.json"
49
+ "integration-rate-limit-wait-r7k2qd.json"
50
50
  ]
51
51
  }
52
52
  }