@imbue-ai/detent 1.12.0 → 1.14.0

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.
@@ -1814,4 +1814,238 @@ describe('builtin schemas: ngrok', () => {
1814
1814
  expect(writeCreds.match(makeRequest({ method: 'POST', path: '/ssh_credentials' }))).toBe(false);
1815
1815
  });
1816
1816
  });
1817
+ describe('builtin schemas: huggingface', () => {
1818
+ const scope = () => builtinRegistry.get('huggingface-api');
1819
+ it('huggingface-api matches the Hub API, the hf.co alias, and repository files', () => {
1820
+ expectSchemaExists('huggingface-api');
1821
+ expect(scope().match(makeRequest({ domain: 'huggingface.co', path: '/api/whoami-v2' }))).toBe(true);
1822
+ expect(scope().match(makeRequest({ domain: 'hf.co', path: '/api/models/gpt2' }))).toBe(true);
1823
+ expect(scope().match(makeRequest({ domain: 'huggingface.co', path: '/gpt2/resolve/main/config.json' }))).toBe(true);
1824
+ expect(scope().match(makeRequest({
1825
+ domain: 'huggingface.co',
1826
+ path: '/datasets/stanfordnlp/imdb/resolve/main/README.md',
1827
+ }))).toBe(true);
1828
+ expect(scope().match(makeRequest({ domain: 'huggingface.co', path: '/openai-community/gpt2.git/info/refs' }))).toBe(true);
1829
+ });
1830
+ it('huggingface-api covers the router, the storage hosts downloads redirect to, and the dataset viewer', () => {
1831
+ expect(scope().match(makeRequest({ domain: 'router.huggingface.co', path: '/v1/chat/completions' }))).toBe(true);
1832
+ for (const domain of [
1833
+ 'us.aws.cdn.hf.co',
1834
+ 'cdn-lfs-us-1.hf.co',
1835
+ 'cas-bridge.xethub.hf.co',
1836
+ 'transfer.xethub.hf.co',
1837
+ ]) {
1838
+ expect(scope().match(makeRequest({ domain, path: '/xet-bridge-us/abc123' }))).toBe(true);
1839
+ }
1840
+ expect(scope().match(makeRequest({ domain: 'datasets-server.huggingface.co', path: '/splits' }))).toBe(true);
1841
+ });
1842
+ it('huggingface-api rejects unrelated domains and the non-API parts of huggingface.co', () => {
1843
+ expect(scope().match(makeRequest({ domain: 'huggingface.example.com' }))).toBe(false);
1844
+ for (const path of ['/', '/mcp', '/oauth/token', '/settings/tokens']) {
1845
+ expect(scope().match(makeRequest({ domain: 'huggingface.co', path }))).toBe(false);
1846
+ }
1847
+ expect(scope().match(makeRequest({ domain: 'gradio-hello-world.hf.space', path: '/' }))).toBe(false);
1848
+ });
1849
+ it('huggingface-read-all matches safe methods, including the HEAD that precedes a download', () => {
1850
+ expectSchemaExists('huggingface-read-all');
1851
+ for (const method of ['GET', 'HEAD', 'OPTIONS']) {
1852
+ expect(builtinRegistry.get('huggingface-read-all').match(makeRequest({
1853
+ method,
1854
+ domain: 'huggingface.co',
1855
+ path: '/gpt2/resolve/main/config.json',
1856
+ }))).toBe(true);
1857
+ }
1858
+ expect(builtinRegistry
1859
+ .get('huggingface-read-all')
1860
+ .match(makeRequest({ method: 'POST', domain: 'huggingface.co', path: '/api/repos/create' }))).toBe(false);
1861
+ });
1862
+ it('huggingface-write-all matches Hub writes but not the paid inference router', () => {
1863
+ expectSchemaExists('huggingface-write-all');
1864
+ const writeAll = builtinRegistry.get('huggingface-write-all');
1865
+ expect(writeAll.match(makeRequest({ method: 'POST', domain: 'huggingface.co', path: '/api/repos/create' }))).toBe(true);
1866
+ expect(writeAll.match(makeRequest({ method: 'POST', domain: 'huggingface.co', path: '/api/jobs/acme' }))).toBe(true);
1867
+ expect(writeAll.match(makeRequest({ method: 'PUT', domain: 'transfer.xethub.hf.co', path: '/xet/abc' }))).toBe(true);
1868
+ expect(writeAll.match(makeRequest({
1869
+ method: 'POST',
1870
+ domain: 'router.huggingface.co',
1871
+ path: '/v1/chat/completions',
1872
+ }))).toBe(false);
1873
+ expect(writeAll.match(makeRequest({ method: 'GET', domain: 'huggingface.co' }))).toBe(false);
1874
+ });
1875
+ it('huggingface-inference matches a POST to the router only', () => {
1876
+ expectSchemaExists('huggingface-inference');
1877
+ expect(builtinRegistry.get('huggingface-inference').match(makeRequest({
1878
+ method: 'POST',
1879
+ domain: 'router.huggingface.co',
1880
+ path: '/v1/chat/completions',
1881
+ }))).toBe(true);
1882
+ expect(builtinRegistry
1883
+ .get('huggingface-inference')
1884
+ .match(makeRequest({ method: 'GET', domain: 'router.huggingface.co' }))).toBe(false);
1885
+ expect(builtinRegistry
1886
+ .get('huggingface-inference')
1887
+ .match(makeRequest({ method: 'POST', domain: 'huggingface.co' }))).toBe(false);
1888
+ });
1889
+ it('huggingface-download covers every transport a repository download uses', () => {
1890
+ expectSchemaExists('huggingface-download');
1891
+ const download = builtinRegistry.get('huggingface-download');
1892
+ expect(download.match(makeRequest({
1893
+ method: 'HEAD',
1894
+ domain: 'huggingface.co',
1895
+ path: '/gpt2/resolve/main/config.json',
1896
+ }))).toBe(true);
1897
+ expect(download.match(makeRequest({
1898
+ method: 'GET',
1899
+ domain: 'huggingface.co',
1900
+ path: '/api/resolve-cache/datasets/stanfordnlp/imdb/abc/README.md',
1901
+ }))).toBe(true);
1902
+ expect(download.match(makeRequest({ method: 'GET', domain: 'us.aws.cdn.hf.co', path: '/xet-bridge-us/abc123' }))).toBe(true);
1903
+ expect(download.match(makeRequest({
1904
+ method: 'GET',
1905
+ domain: 'huggingface.co',
1906
+ path: '/openai-community/gpt2.git/info/refs',
1907
+ queryParams: { service: 'git-upload-pack' },
1908
+ }))).toBe(true);
1909
+ expect(download.match(makeRequest({
1910
+ method: 'POST',
1911
+ domain: 'huggingface.co',
1912
+ path: '/openai-community/gpt2.git/info/lfs/objects/batch',
1913
+ }))).toBe(true);
1914
+ expect(download.match(makeRequest({
1915
+ method: 'GET',
1916
+ domain: 'huggingface.co',
1917
+ path: '/openai-community/gpt2.git/info/refs',
1918
+ queryParams: { service: 'git-receive-pack' },
1919
+ }))).toBe(false);
1920
+ expect(download.match(makeRequest({
1921
+ method: 'POST',
1922
+ domain: 'huggingface.co',
1923
+ path: '/openai-community/gpt2.git/git-receive-pack',
1924
+ }))).toBe(false);
1925
+ expect(download.match(makeRequest({ method: 'GET', domain: 'huggingface.co', path: '/api/models' }))).toBe(false);
1926
+ });
1927
+ });
1928
+ describe('builtin schemas: openrouter', () => {
1929
+ it('openrouter-api matches openrouter.ai', () => {
1930
+ expectSchemaExists('openrouter-api');
1931
+ expect(builtinRegistry
1932
+ .get('openrouter-api')
1933
+ .match(makeRequest({ domain: 'openrouter.ai', path: '/api/v1/chat/completions' }))).toBe(true);
1934
+ });
1935
+ it('openrouter-api rejects unrelated domains', () => {
1936
+ expect(builtinRegistry
1937
+ .get('openrouter-api')
1938
+ .match(makeRequest({ domain: 'openrouter.example.com', path: '/api/v1/models' }))).toBe(false);
1939
+ });
1940
+ it('openrouter-api rejects non-API paths on openrouter.ai', () => {
1941
+ expect(builtinRegistry
1942
+ .get('openrouter-api')
1943
+ .match(makeRequest({ domain: 'openrouter.ai', path: '/models' }))).toBe(false);
1944
+ });
1945
+ it('openrouter-read-all matches GET but not writes', () => {
1946
+ expectSchemaExists('openrouter-read-all');
1947
+ expect(builtinRegistry
1948
+ .get('openrouter-read-all')
1949
+ .match(makeRequest({ method: 'GET', domain: 'openrouter.ai', path: '/api/v1/models' }))).toBe(true);
1950
+ expect(builtinRegistry
1951
+ .get('openrouter-read-all')
1952
+ .match(makeRequest({ method: 'POST', domain: 'openrouter.ai', path: '/api/v1/chat/completions' }))).toBe(false);
1953
+ });
1954
+ it('openrouter-write-all matches writes but not GET', () => {
1955
+ expectSchemaExists('openrouter-write-all');
1956
+ const write = builtinRegistry.get('openrouter-write-all');
1957
+ expect(write.match(makeRequest({ method: 'POST', domain: 'openrouter.ai', path: '/api/v1/keys' }))).toBe(true);
1958
+ expect(write.match(makeRequest({ method: 'DELETE', domain: 'openrouter.ai', path: '/api/v1/keys/abc' }))).toBe(true);
1959
+ expect(write.match(makeRequest({ method: 'GET', domain: 'openrouter.ai' }))).toBe(false);
1960
+ });
1961
+ it('openrouter-inference matches the credit-consuming model endpoints only', () => {
1962
+ expectSchemaExists('openrouter-inference');
1963
+ const inference = builtinRegistry.get('openrouter-inference');
1964
+ // Every model-invoking endpoint in the OpenRouter OpenAPI spec.
1965
+ const inferencePaths = [
1966
+ '/api/v1/chat/completions',
1967
+ '/api/v1/messages',
1968
+ '/api/v1/responses',
1969
+ '/api/v1/embeddings',
1970
+ '/api/v1/rerank',
1971
+ '/api/v1/images',
1972
+ '/api/v1/videos',
1973
+ '/api/v1/audio/speech',
1974
+ '/api/v1/audio/transcriptions',
1975
+ ];
1976
+ for (const path of inferencePaths) {
1977
+ expect(inference.match(makeRequest({ method: 'POST', domain: 'openrouter.ai', path })), `expected inference to match POST ${path}`).toBe(true);
1978
+ }
1979
+ // Account/key management writes and read-side GETs are excluded.
1980
+ expect(inference.match(makeRequest({ method: 'POST', domain: 'openrouter.ai', path: '/api/v1/keys' }))).toBe(false);
1981
+ expect(inference.match(makeRequest({
1982
+ method: 'POST',
1983
+ domain: 'openrouter.ai',
1984
+ path: '/api/v1/generation/feedback',
1985
+ }))).toBe(false);
1986
+ expect(inference.match(makeRequest({ method: 'GET', domain: 'openrouter.ai', path: '/api/v1/chat/completions' }))).toBe(false);
1987
+ });
1988
+ });
1989
+ describe('builtin schemas: tailscale', () => {
1990
+ it('tailscale-api matches api.tailscale.com under /api/', () => {
1991
+ expectSchemaExists('tailscale-api');
1992
+ const scope = builtinRegistry.get('tailscale-api');
1993
+ expect(scope.match(makeRequest({ domain: 'api.tailscale.com', path: '/api/v2/tailnet/example.com/users' }))).toBe(true);
1994
+ expect(scope.match(makeRequest({ domain: 'api.tailscale.com', path: '/api/v2/tailnet/example.com/keys' }))).toBe(true);
1995
+ });
1996
+ it('tailscale-api rejects unrelated domains', () => {
1997
+ expect(builtinRegistry
1998
+ .get('tailscale-api')
1999
+ .match(makeRequest({ domain: 'api.tailscale.com.example.com', path: '/api/v2/' }))).toBe(false);
2000
+ });
2001
+ it('tailscale-api rejects the admin console and sign-in hosts', () => {
2002
+ const scope = builtinRegistry.get('tailscale-api');
2003
+ expect(scope.match(makeRequest({ domain: 'console.tailscale.com', path: '/admin/users' }))).toBe(false);
2004
+ expect(scope.match(makeRequest({ domain: 'login.tailscale.com', path: '/admin' }))).toBe(false);
2005
+ });
2006
+ it('tailscale-api rejects non-API paths on api.tailscale.com', () => {
2007
+ expect(builtinRegistry
2008
+ .get('tailscale-api')
2009
+ .match(makeRequest({ domain: 'api.tailscale.com', path: '/' }))).toBe(false);
2010
+ });
2011
+ it('tailscale-read-all matches GET but not writes', () => {
2012
+ expectSchemaExists('tailscale-read-all');
2013
+ const read = builtinRegistry.get('tailscale-read-all');
2014
+ expect(read.match(makeRequest({
2015
+ method: 'GET',
2016
+ domain: 'api.tailscale.com',
2017
+ path: '/api/v2/tailnet/example.com/users',
2018
+ }))).toBe(true);
2019
+ expect(read.match(makeRequest({
2020
+ method: 'HEAD',
2021
+ domain: 'api.tailscale.com',
2022
+ path: '/api/v2/tailnet/example.com/users',
2023
+ }))).toBe(true);
2024
+ expect(read.match(makeRequest({
2025
+ method: 'POST',
2026
+ domain: 'api.tailscale.com',
2027
+ path: '/api/v2/users/123/role',
2028
+ }))).toBe(false);
2029
+ });
2030
+ it('tailscale-write-all matches writes but not GET', () => {
2031
+ expectSchemaExists('tailscale-write-all');
2032
+ const write = builtinRegistry.get('tailscale-write-all');
2033
+ expect(write.match(makeRequest({ method: 'POST', domain: 'api.tailscale.com', path: '/api/v2/users/123/role' }))).toBe(true);
2034
+ expect(write.match(makeRequest({
2035
+ method: 'DELETE',
2036
+ domain: 'api.tailscale.com',
2037
+ path: '/api/v2/tailnet/example.com/keys/k123',
2038
+ }))).toBe(true);
2039
+ expect(write.match(makeRequest({
2040
+ method: 'PATCH',
2041
+ domain: 'api.tailscale.com',
2042
+ path: '/api/v2/tailnet/example.com/settings',
2043
+ }))).toBe(true);
2044
+ expect(write.match(makeRequest({
2045
+ method: 'GET',
2046
+ domain: 'api.tailscale.com',
2047
+ path: '/api/v2/tailnet/example.com/users',
2048
+ }))).toBe(false);
2049
+ });
2050
+ });
1817
2051
  //# sourceMappingURL=builtinSchemas.test.js.map