@stigmer/react-core 0.4.1 → 0.4.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/agent/appUser.d.ts +18 -0
- package/agent/appUser.d.ts.map +1 -0
- package/agent/appUser.js +26 -0
- package/agent/appUser.js.map +1 -0
- package/index.d.ts +5 -1
- package/index.d.ts.map +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/internal/useKeyedState.d.ts +6 -0
- package/internal/useKeyedState.d.ts.map +1 -0
- package/internal/useKeyedState.js +56 -0
- package/internal/useKeyedState.js.map +1 -0
- package/internal.d.ts +5 -0
- package/internal.d.ts.map +1 -1
- package/internal.js +4 -0
- package/internal.js.map +1 -1
- package/models/registry.d.ts +12 -0
- package/models/registry.d.ts.map +1 -1
- package/models/registry.js +17 -1
- package/models/registry.js.map +1 -1
- package/package.json +3 -3
- package/run/useAnswerCustomToolUse.d.ts +3 -1
- package/run/useAnswerCustomToolUse.d.ts.map +1 -1
- package/run/useAnswerCustomToolUse.js +9 -4
- package/run/useAnswerCustomToolUse.js.map +1 -1
- package/run/useAnswerToolUse.d.ts +16 -1
- package/run/useAnswerToolUse.d.ts.map +1 -1
- package/run/useAnswerToolUse.js +29 -9
- package/run/useAnswerToolUse.js.map +1 -1
- package/run/useCreateRun.d.ts +3 -1
- package/run/useCreateRun.d.ts.map +1 -1
- package/run/useCreateRun.js +11 -7
- package/run/useCreateRun.js.map +1 -1
- package/run/useReviewFileChanges.d.ts +18 -2
- package/run/useReviewFileChanges.d.ts.map +1 -1
- package/run/useReviewFileChanges.js +21 -7
- package/run/useReviewFileChanges.js.map +1 -1
- package/run/useRunActions.d.ts +10 -3
- package/run/useRunActions.d.ts.map +1 -1
- package/run/useRunActions.js +22 -18
- package/run/useRunActions.js.map +1 -1
- package/session/useSessionConversation.d.ts.map +1 -1
- package/session/useSessionConversation.js +10 -6
- package/session/useSessionConversation.js.map +1 -1
- package/src/agent/appUser.ts +26 -0
- package/src/index.ts +5 -0
- package/src/internal/useKeyedState.ts +70 -0
- package/src/internal.ts +5 -0
- package/src/models/registry.ts +19 -1
- package/src/run/useAnswerCustomToolUse.ts +9 -4
- package/src/run/useAnswerToolUse.ts +33 -9
- package/src/run/useCreateRun.ts +11 -7
- package/src/run/useReviewFileChanges.ts +29 -8
- package/src/run/useRunActions.ts +43 -25
- package/src/session/useSessionConversation.ts +10 -6
- package/src/tool-tokens/ToolTokensProvider.tsx +176 -0
- package/src/tool-tokens/tool-tokens.ts +114 -0
- package/src/vault/address.ts +54 -0
- package/tool-tokens/ToolTokensProvider.d.ts +44 -0
- package/tool-tokens/ToolTokensProvider.d.ts.map +1 -0
- package/tool-tokens/ToolTokensProvider.js +135 -0
- package/tool-tokens/ToolTokensProvider.js.map +1 -0
- package/tool-tokens/tool-tokens.d.ts +68 -0
- package/tool-tokens/tool-tokens.d.ts.map +1 -0
- package/tool-tokens/tool-tokens.js +73 -0
- package/tool-tokens/tool-tokens.js.map +1 -0
- package/vault/address.d.ts +24 -0
- package/vault/address.d.ts.map +1 -0
- package/vault/address.js +57 -0
- package/vault/address.js.map +1 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// A host's tool tokens: the signed-in user's own token for each of the
|
|
3
|
+
// host's tool servers, written as that user's own login before every
|
|
4
|
+
// request that starts work on a turn.
|
|
5
|
+
//
|
|
6
|
+
// Why a write, and why before each request: a turn's values are read by
|
|
7
|
+
// the runner when each piece of the turn's work starts, from the vaults as
|
|
8
|
+
// they are at that moment (the server's `domain/vault/values.ts`), and the
|
|
9
|
+
// server keeps no copy between. An app user's own turn reads the logins in
|
|
10
|
+
// their own My vault last, each only for the tool at the login's address
|
|
11
|
+
// (the server's `domain/vault/resolve.ts`, its fifth source). So the
|
|
12
|
+
// user's current token, saved there just before a message is sent or an
|
|
13
|
+
// approval answered, is what the tool receives for the work that request
|
|
14
|
+
// starts, and no other person's turn ever reads it. A token handed with the
|
|
15
|
+
// message instead would have to wait on the server until the runner asked,
|
|
16
|
+
// which can be hours across an approval.
|
|
17
|
+
//
|
|
18
|
+
// Each write replaces the last one in place; nothing renews a token written
|
|
19
|
+
// this way (only a sign-in's login is renewed), so an expired token reaches
|
|
20
|
+
// the tool server as it is and the server's refusal is the turn's answer.
|
|
21
|
+
//
|
|
22
|
+
// The context is read by the four hooks that start work on a turn
|
|
23
|
+
// (`useCreateRun`, `useAnswerToolUse`, `useAnswerCustomToolUse`,
|
|
24
|
+
// `useRunActions`' resume and recover) and by the React kit's setup, which
|
|
25
|
+
// offers no sign-in for an address the host fills.
|
|
26
|
+
import { createContext, useContext } from "react";
|
|
27
|
+
/**
|
|
28
|
+
* A send that did not happen because one of the host's token functions
|
|
29
|
+
* threw or gave no token. Nothing was sent: not the message, not the
|
|
30
|
+
* answer, not any token. `message` is written for the person in front of
|
|
31
|
+
* the chat, who reads it where the send failed; `address` names the tool
|
|
32
|
+
* server whose function failed, and `cause` is what it threw, if it threw.
|
|
33
|
+
* The token itself is never part of it.
|
|
34
|
+
*/
|
|
35
|
+
export class ToolTokenUnavailableError extends Error {
|
|
36
|
+
/** The tool server whose token function failed, as the host keyed it. */
|
|
37
|
+
address;
|
|
38
|
+
constructor(address, cause) {
|
|
39
|
+
super("Your sign-in to this app's tools could not be read, so nothing was sent. Try again, or sign in to the app again.", {
|
|
40
|
+
cause,
|
|
41
|
+
});
|
|
42
|
+
this.name = "ToolTokenUnavailableError";
|
|
43
|
+
this.address = address;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The host's tool tokens for the conversation below, or `null` where none
|
|
48
|
+
* were given.
|
|
49
|
+
*
|
|
50
|
+
* @internal Provided by `ToolTokensProvider`.
|
|
51
|
+
*/
|
|
52
|
+
export const ToolTokensContext = createContext(null);
|
|
53
|
+
/**
|
|
54
|
+
* The host's tool tokens from the nearest `ToolTokensProvider`, or `null`.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export function useToolTokens() {
|
|
59
|
+
return useContext(ToolTokensContext);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Runs `send` after the host's tool tokens are written, or at once where
|
|
63
|
+
* none were given: the one order every hook that starts work on a turn
|
|
64
|
+
* keeps.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export async function withToolTokens(tokens, send) {
|
|
69
|
+
if (tokens !== null)
|
|
70
|
+
await tokens.refresh();
|
|
71
|
+
return send();
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=tool-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-tokens.js","sourceRoot":"","sources":["../src/tool-tokens/tool-tokens.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,uEAAuE;AACvE,qEAAqE;AACrE,sCAAsC;AACtC,EAAE;AACF,wEAAwE;AACxE,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,qEAAqE;AACrE,wEAAwE;AACxE,yEAAyE;AACzE,4EAA4E;AAC5E,2EAA2E;AAC3E,yCAAyC;AACzC,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,2EAA2E;AAC3E,mDAAmD;AAEnD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAmBlD;;;;;;;GAOG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,yEAAyE;IAChE,OAAO,CAAS;IAEzB,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,kHAAkH,EAAE;YACxH,KAAK;SACN,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAqBD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,UAAU,CAAC,iBAAiB,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,MAA8B,EAAE,IAAsB;IAC5F,IAAI,MAAM,KAAK,IAAI;QAAE,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAC5C,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address a vault connection is saved at, by the server's one rule
|
|
3
|
+
* (`domain/vault/address.ts` in the server): a tool's address is its full
|
|
4
|
+
* URL, with scheme and host lowercased, a default port dropped, one trailing
|
|
5
|
+
* slash trimmed, query and fragment dropped; only an http or https URL
|
|
6
|
+
* without credentials in it is one. A Git host's address is its bare host
|
|
7
|
+
* name, lowercased, its default port dropped (`github.com`).
|
|
8
|
+
*
|
|
9
|
+
* The server normalizes every saved address itself. This mirror lives here,
|
|
10
|
+
* below the React kit, because two layers match an address before anything
|
|
11
|
+
* is saved: `ToolTokensProvider` refuses a host's key the server would
|
|
12
|
+
* refuse, and the kit's setup matches a tool against the logins that fill
|
|
13
|
+
* it. The kit's `vault/address.ts` builds its tool and Git-host rules on it.
|
|
14
|
+
*
|
|
15
|
+
* Pinned by __tests__/address.test.ts.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes an address in either shape: a URL (`https://mcp.linear.app/mcp/`)
|
|
19
|
+
* becomes a tool address, anything else a bare host. Returns `null` for input
|
|
20
|
+
* the server would refuse (an unparseable URL, a scheme other than http or
|
|
21
|
+
* https, credentials in the URL, a placeholder, a blank).
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeAddress(input: string): string | null;
|
|
24
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/vault/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAUH;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgB7D"}
|
package/vault/address.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address a vault connection is saved at, by the server's one rule
|
|
3
|
+
* (`domain/vault/address.ts` in the server): a tool's address is its full
|
|
4
|
+
* URL, with scheme and host lowercased, a default port dropped, one trailing
|
|
5
|
+
* slash trimmed, query and fragment dropped; only an http or https URL
|
|
6
|
+
* without credentials in it is one. A Git host's address is its bare host
|
|
7
|
+
* name, lowercased, its default port dropped (`github.com`).
|
|
8
|
+
*
|
|
9
|
+
* The server normalizes every saved address itself. This mirror lives here,
|
|
10
|
+
* below the React kit, because two layers match an address before anything
|
|
11
|
+
* is saved: `ToolTokensProvider` refuses a host's key the server would
|
|
12
|
+
* refuse, and the kit's setup matches a tool against the logins that fill
|
|
13
|
+
* it. The kit's `vault/address.ts` builds its tool and Git-host rules on it.
|
|
14
|
+
*
|
|
15
|
+
* Pinned by __tests__/address.test.ts.
|
|
16
|
+
*/
|
|
17
|
+
const DEFAULT_PORTS = {
|
|
18
|
+
"http:": "80",
|
|
19
|
+
"https:": "443",
|
|
20
|
+
};
|
|
21
|
+
/** A bare host: labels of letters, digits and hyphens, optionally with a port. */
|
|
22
|
+
const BARE_HOST = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*(:[0-9]{1,5})?$/;
|
|
23
|
+
/**
|
|
24
|
+
* Normalizes an address in either shape: a URL (`https://mcp.linear.app/mcp/`)
|
|
25
|
+
* becomes a tool address, anything else a bare host. Returns `null` for input
|
|
26
|
+
* the server would refuse (an unparseable URL, a scheme other than http or
|
|
27
|
+
* https, credentials in the URL, a placeholder, a blank).
|
|
28
|
+
*/
|
|
29
|
+
export function normalizeAddress(input) {
|
|
30
|
+
const trimmed = input.trim();
|
|
31
|
+
if (trimmed === "" || trimmed.includes("${"))
|
|
32
|
+
return null;
|
|
33
|
+
if (!trimmed.includes("://"))
|
|
34
|
+
return normalizeHost(trimmed);
|
|
35
|
+
let url;
|
|
36
|
+
try {
|
|
37
|
+
url = new URL(trimmed);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
43
|
+
return null;
|
|
44
|
+
if (url.username !== "" || url.password !== "")
|
|
45
|
+
return null;
|
|
46
|
+
const port = url.port !== "" && DEFAULT_PORTS[url.protocol] !== url.port ? `:${url.port}` : "";
|
|
47
|
+
let path = url.pathname;
|
|
48
|
+
if (path.endsWith("/"))
|
|
49
|
+
path = path.slice(0, -1);
|
|
50
|
+
return `${url.protocol}//${url.hostname.toLowerCase()}${port}${path}`;
|
|
51
|
+
}
|
|
52
|
+
/** A bare host name, lowercased, one trailing slash and the HTTPS port dropped; `null` when it is not one. */
|
|
53
|
+
function normalizeHost(input) {
|
|
54
|
+
const host = input.trim().toLowerCase().replace(/\/$/, "");
|
|
55
|
+
return BARE_HOST.test(host) ? host.replace(/:443$/, "") : null;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/vault/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,aAAa,GAAqC;IACtD,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,KAAK;CAChB,CAAC;AAEF,kFAAkF;AAClF,MAAM,SAAS,GAAG,iFAAiF,CAAC;AAEpG;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,MAAM,OAAO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