@yaks/connections 0.0.0-stage → 0.2.36

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 (184) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +609 -2
  3. package/_dist/authorize.d.ts +38 -0
  4. package/_dist/authorize.d.ts.map +1 -0
  5. package/_dist/authorize_cli.d.ts +12 -0
  6. package/_dist/authorize_cli.d.ts.map +1 -0
  7. package/_dist/brokers.d.ts +66 -0
  8. package/_dist/brokers.d.ts.map +1 -0
  9. package/_dist/catalog.d.ts +33 -0
  10. package/_dist/catalog.d.ts.map +1 -0
  11. package/_dist/cli.d.ts +3 -0
  12. package/_dist/cli.d.ts.map +1 -0
  13. package/_dist/clients.d.ts +18 -0
  14. package/_dist/clients.d.ts.map +1 -0
  15. package/_dist/connections.d.ts +296 -0
  16. package/_dist/connections.d.ts.map +1 -0
  17. package/_dist/effects.d.ts +15 -0
  18. package/_dist/effects.d.ts.map +1 -0
  19. package/_dist/field.d.ts +17 -0
  20. package/_dist/field.d.ts.map +1 -0
  21. package/_dist/form.d.ts +49 -0
  22. package/_dist/form.d.ts.map +1 -0
  23. package/_dist/given.d.ts +10 -0
  24. package/_dist/given.d.ts.map +1 -0
  25. package/_dist/graph.d.ts +15 -0
  26. package/_dist/graph.d.ts.map +1 -0
  27. package/_dist/history.d.ts +4 -0
  28. package/_dist/history.d.ts.map +1 -0
  29. package/_dist/identity.d.ts +9 -0
  30. package/_dist/identity.d.ts.map +1 -0
  31. package/_dist/integrations.d.ts +196 -0
  32. package/_dist/integrations.d.ts.map +1 -0
  33. package/_dist/loopback.d.ts +7 -0
  34. package/_dist/loopback.d.ts.map +1 -0
  35. package/_dist/mcp-retirement.d.ts +33 -0
  36. package/_dist/mcp-retirement.d.ts.map +1 -0
  37. package/_dist/mcp.d.ts +179 -0
  38. package/_dist/mcp.d.ts.map +1 -0
  39. package/_dist/mod.d.ts +70 -0
  40. package/_dist/mod.d.ts.map +1 -0
  41. package/_dist/paste.d.ts +13 -0
  42. package/_dist/paste.d.ts.map +1 -0
  43. package/_dist/requests.d.ts +30 -0
  44. package/_dist/requests.d.ts.map +1 -0
  45. package/_dist/services.d.ts +25 -0
  46. package/_dist/services.d.ts.map +1 -0
  47. package/_dist/sign-in.d.ts +9 -0
  48. package/_dist/sign-in.d.ts.map +1 -0
  49. package/_dist/signin-mail.d.ts +12 -0
  50. package/_dist/signin-mail.d.ts.map +1 -0
  51. package/_dist/signin.d.ts +19 -0
  52. package/_dist/signin.d.ts.map +1 -0
  53. package/_dist/sources.d.ts +61 -0
  54. package/_dist/sources.d.ts.map +1 -0
  55. package/_dist/tools.d.ts +3 -0
  56. package/_dist/tools.d.ts.map +1 -0
  57. package/_dist/views.d.ts +3 -0
  58. package/_dist/views.d.ts.map +1 -0
  59. package/_dist/vocab.d.ts +6 -0
  60. package/_dist/vocab.d.ts.map +1 -0
  61. package/_dist/yaks-app.d.ts +29 -0
  62. package/_dist/yaks-app.d.ts.map +1 -0
  63. package/anthropic.json +12 -0
  64. package/auth_command.js +69 -0
  65. package/auth_command.js.map +1 -0
  66. package/auth_command.ts +74 -0
  67. package/authorize.js +89 -0
  68. package/authorize.js.map +1 -0
  69. package/authorize.ts +138 -0
  70. package/authorize_cli.js +167 -0
  71. package/authorize_cli.js.map +1 -0
  72. package/authorize_cli.ts +211 -0
  73. package/brokers.js +318 -0
  74. package/brokers.js.map +1 -0
  75. package/brokers.ts +423 -0
  76. package/canva.json +32 -0
  77. package/catalog.js +178 -0
  78. package/catalog.js.map +1 -0
  79. package/catalog.ts +216 -0
  80. package/cli.js +30 -0
  81. package/cli.js.map +1 -0
  82. package/cli.ts +26 -0
  83. package/clients.js +34 -0
  84. package/clients.js.map +1 -0
  85. package/clients.ts +65 -0
  86. package/connections.js +1961 -0
  87. package/connections.js.map +1 -0
  88. package/connections.ts +2561 -0
  89. package/deno.json +1 -0
  90. package/discord-account.json +22 -0
  91. package/discord-bot.json +20 -0
  92. package/discord.json +26 -0
  93. package/effects.js +168 -0
  94. package/effects.js.map +1 -0
  95. package/effects.ts +160 -0
  96. package/elevenlabs.json +18 -0
  97. package/facebook.json +18 -0
  98. package/field.js +19 -0
  99. package/field.js.map +1 -0
  100. package/field.ts +31 -0
  101. package/form.js +112 -0
  102. package/form.js.map +1 -0
  103. package/form.ts +178 -0
  104. package/git-config.js +44 -0
  105. package/git-config.js.map +1 -0
  106. package/git-config.ts +26 -0
  107. package/given.js +83 -0
  108. package/given.js.map +1 -0
  109. package/given.ts +88 -0
  110. package/gmail-mailbox.json +29 -0
  111. package/gmail.json +31 -0
  112. package/google-calendar.json +31 -0
  113. package/google-drive.json +31 -0
  114. package/google-search-console.json +29 -0
  115. package/graph.js +36 -0
  116. package/graph.js.map +1 -0
  117. package/graph.ts +52 -0
  118. package/history.js +31 -0
  119. package/history.js.map +1 -0
  120. package/history.ts +32 -0
  121. package/identity.js +15 -0
  122. package/identity.js.map +1 -0
  123. package/identity.ts +18 -0
  124. package/integrations.js +493 -0
  125. package/integrations.js.map +1 -0
  126. package/integrations.ts +725 -0
  127. package/loopback.js +72 -0
  128. package/loopback.js.map +1 -0
  129. package/loopback.ts +89 -0
  130. package/lulu.json +32 -0
  131. package/mcp-retirement.js +133 -0
  132. package/mcp-retirement.js.map +1 -0
  133. package/mcp-retirement.ts +200 -0
  134. package/mcp-signin.js +14 -0
  135. package/mcp-signin.js.map +1 -0
  136. package/mcp-signin.ts +13 -0
  137. package/mcp.js +1036 -0
  138. package/mcp.js.map +1 -0
  139. package/mcp.ts +1283 -0
  140. package/mod.js +70 -0
  141. package/mod.js.map +1 -0
  142. package/mod.ts +216 -0
  143. package/openai-api.json +12 -0
  144. package/openai.json +25 -0
  145. package/openrouter.json +14 -0
  146. package/package.json +89 -4
  147. package/paste.js +36 -0
  148. package/paste.js.map +1 -0
  149. package/paste.ts +55 -0
  150. package/requests.js +137 -0
  151. package/requests.js.map +1 -0
  152. package/requests.ts +200 -0
  153. package/services.js +84 -0
  154. package/services.js.map +1 -0
  155. package/services.ts +111 -0
  156. package/sign-in.js +36 -0
  157. package/sign-in.js.map +1 -0
  158. package/sign-in.ts +53 -0
  159. package/signin-mail.js +29 -0
  160. package/signin-mail.js.map +1 -0
  161. package/signin-mail.ts +56 -0
  162. package/signin.js +68 -0
  163. package/signin.js.map +1 -0
  164. package/signin.ts +109 -0
  165. package/slack.json +90 -0
  166. package/sources.js +178 -0
  167. package/sources.js.map +1 -0
  168. package/sources.ts +237 -0
  169. package/tools.js +39 -0
  170. package/tools.js.map +1 -0
  171. package/tools.ts +46 -0
  172. package/views.js +85 -0
  173. package/views.js.map +1 -0
  174. package/views.ts +89 -0
  175. package/visitor-defaults.json +8 -0
  176. package/vocab.js +17 -0
  177. package/vocab.js.map +1 -0
  178. package/vocab.json +863 -0
  179. package/vocab.ts +18 -0
  180. package/voipms.json +32 -0
  181. package/yaks-app.js +159 -0
  182. package/yaks-app.js.map +1 -0
  183. package/yaks-app.ts +177 -0
  184. package/youtube.json +26 -0
@@ -0,0 +1,12 @@
1
+ import type { Bundle } from "@yaks/graph";
2
+ import { type And } from "@yaks/query";
3
+ import type { Read } from "./integrations.js";
4
+ export declare let codeIn: (letters: Bundle[], address: string, since: number) => string | null;
5
+ export declare let lettersFor: (address: string, since: number) => And;
6
+ export declare let codeFor: (read: Read, address: string, since: number, opts?: {
7
+ wait?: number;
8
+ poll?: number;
9
+ now?: () => number;
10
+ sleep?: (ms: number) => Promise<void>;
11
+ }) => Promise<string>;
12
+ //# sourceMappingURL=signin-mail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signin-mail.d.ts","sources":["../signin-mail.ts"],"names":[],"mappings":"AACA,cAAc,MAAM,2BAAsC;AAC1D,SAAS,KAAK,GAAG,2BAA0D;AAC3E,cAAc,IAAI,4BAA2B;AAK7C,OAAO,YAAI,SACT,SAAS,UACT,SAAS,MAAM,EACf,OAAO,MAAM,KACZ,MAAM,GAAG,IAAI,CAQf;AACD,OAAO,YAAI,aAAc,SAAS,MAAM,EAAE,OAAO,MAAM,KAAG,IAMvD;AACH,OAAO,YAAI,UACT,MAAM,MACN,SAAS,MAAM,EACf,OAAO,MAAM,EACb;EACE,OAAO,MAAM;EACb,OAAO,MAAM;EACb,YAAY,MAAM;EAClB,SAAS,IAAI,MAAM,KAAK,QAAQ,IAAI;MAErC,QAAQ,MAAM,EAiBhB"}
@@ -0,0 +1,19 @@
1
+ import type { Eid, Graph } from "@yaks/graph";
2
+ import type { Vault } from "@yaks/secrets";
3
+ /** The registered browser return address for a local sign-in. */ export declare const REDIRECT: 'http://localhost:8765/oauth/callback';
4
+ export type SignIns = {
5
+ key: (owner: Eid, integration: string) => Promise<string | undefined>;
6
+ refresh: (owner: Eid, integration: string, stale: string) => Promise<string | undefined>;
7
+ begin: (owner: Eid, integration: string, redirect?: string) => Promise<{
8
+ url: string;
9
+ redirectUrl: string;
10
+ }>;
11
+ complete: (owner: Eid, integration: string, callback: string, session?: string) => Promise<void>;
12
+ cancel: (owner?: Eid) => void;
13
+ };
14
+ export declare const signins: (h: {
15
+ g: Graph;
16
+ vault: Vault;
17
+ fetch?: typeof fetch;
18
+ }) => SignIns;
19
+ //# sourceMappingURL=signin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signin.d.ts","sources":["../signin.ts"],"names":[],"mappings":"AAYA,cAAc,GAAG,EAAE,KAAK,2BAAgC;AACxD,cAAc,KAAK,6BAAkC;AAGrD,+DAA+D,GAC/D,OAAO,cAAM,UAAW,uCAAsC;AAE9D,YAAY;EACV,MAAM,OAAO,KAAK,aAAa,MAAM,KAAK,QAAQ,MAAM,GAAG,SAAS;EACpE,UACE,OAAO,KACP,aAAa,MAAM,EACnB,OAAO,MAAM,KACV,QAAQ,MAAM,GAAG,SAAS;EAC/B,QACE,OAAO,KACP,aAAa,MAAM,EACnB,WAAW,MAAM,KACd;IAAU,KAAK,MAAM;IAAE,aAAa,MAAM;;EAC/C,WACE,OAAO,KACP,aAAa,MAAM,EACnB,UAAU,MAAM,EAChB,UAAU,MAAM,KACb,QAAQ,IAAI;EACjB,SAAS,QAAQ,QAAQ,IAAI;;AAG/B,OAAO,cAAM,UAAW;EACtB,GAAG;EACH,OAAO;EACP,eAAe;MACb,QAgEH"}
@@ -0,0 +1,61 @@
1
+ import type { Bundle, Eid } from "@yaks/graph";
2
+ import { type Read } from "./integrations.js";
3
+ /** The kinds of source a person grants an app by address. */ export type Kind = 'mcp' | 'connection' | 'service';
4
+ /** One source a person can grant, as the page asking them shows it. */ export type Grantable = {
5
+ at: string;
6
+ title: string;
7
+ about: string;
8
+ };
9
+ /** A service's address for the app holding its connection. */ export declare let serviceAt: (service: string, app: string) => string;
10
+ /** The kind an address names, and the rest of it.
11
+ *
12
+ * ```ts
13
+ * import { assertEquals } from '@std/assert'
14
+ * assertEquals(addressed('mcp:abc'), { kind: 'mcp', rest: 'abc' })
15
+ * assertEquals(addressed('connection:'), { kind: 'connection', rest: '' })
16
+ * assertEquals(addressed('recipes'), undefined)
17
+ * ```
18
+ */ export declare let addressed: (at: string) => {
19
+ kind: Kind;
20
+ rest: string;
21
+ } | undefined;
22
+ /** Every source of `person`'s that `app` holds their grant to: the far end
23
+ * of each `uses` link from the app that the person holds, whole. */ export declare let grantedTo: (read: Read, a: {
24
+ app: Eid;
25
+ person: Eid;
26
+ }) => Promise<Bundle[]>;
27
+ /** Every source of `person`'s that `app` holds their grant to, by address. */ export declare let grantsOf: (read: Read, a: {
28
+ app: Eid;
29
+ person: Eid;
30
+ }) => Promise<string[]>;
31
+ /** The apps each of `eids` (sources a person holds) is granted to, by the
32
+ * source's eid. */ export declare let grantees: (read: Read, eids: Eid[]) => Promise<Map<Eid, Eid[]>>;
33
+ /** Whether `person` granted `app` the source at `at`, read now. */ export declare let granted: (read: Read, a: {
34
+ app: Eid;
35
+ person: Eid;
36
+ at: string;
37
+ }) => Promise<boolean>;
38
+ /** The source the link from an app to `eid` reaches, and the link, where the
39
+ * person holds it and the link stands. */ export declare let grantOf: (read: Read, a: {
40
+ app: Eid;
41
+ person: Eid;
42
+ eid: Eid;
43
+ }) => Promise<{
44
+ source: Bundle;
45
+ link: Bundle;
46
+ } | undefined>;
47
+ /** The person's grant of one of their sources to an app: the link, spent by
48
+ * them alone and naming no binding. Only the person who holds the source
49
+ * grants it. */ export declare let grant: (read: Read, a: {
50
+ app: Eid;
51
+ person: Eid;
52
+ at: string;
53
+ }) => Promise<Bundle[]>;
54
+ /** Take back a grant: the link goes, and the next call through it is refused. */ export declare let revoke: (a: {
55
+ app: Eid;
56
+ at: string;
57
+ }) => Bundle[];
58
+ /** What `person` may grant at `at`: the one source it names, or each of its
59
+ * kind they hold (`mcp:`, `connection:`), with what it is and where it
60
+ * reaches. A connection is offered once connected with hosts to send to. */ export declare let grantable: (read: Read, person: Eid, at: string) => Promise<Grantable[]>;
61
+ //# sourceMappingURL=sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.d.ts","sources":["../sources.ts"],"names":[],"mappings":"AAkBA,cAAc,MAAM,EAAQ,GAAG,2BAAgC;AAI/D,SAAkC,KAAK,IAAI,4BAA2B;AAEtE,2DAA2D,GAC3D,YAAY,OAAO,QAAQ,eAAe;AAE1C,qEAAqE,GACrE,YAAY;EAAc,IAAI,MAAM;EAAE,OAAO,MAAM;EAAE,OAAO,MAAM;;AAQlE,4DAA4D,GAC5D,OAAO,YAAI,YAAa,SAAS,MAAM,EAAE,KAAK,MAAM,KAAG,MAAM,CAChC;AAE7B;;;;;;;;CAQC,GACD,OAAO,YAAI,YACT,IAAI,MAAM;EACP,MAAM;EAAM,MAAM,MAAM;IAAK,SAAS,CAG1C;AAuCD;kEACkE,GAClE,OAAO,YAAI,YACT,MAAM,MACN;EAAK,KAAK;EAAK,QAAQ;MACtB,QAAQ,UAMV;AAED,4EAA4E,GAC5E,OAAO,YAAI,WACT,MAAM,MACN;EAAK,KAAK;EAAK,QAAQ;MACtB,QAAQ,MAAM,IAGhB;AASD;iBACiB,GACjB,OAAO,YAAI,WACT,MAAM,MACN,MAAM,UACL,QAAQ,IAAI,KAAK,QAQnB;AAED,iEAAiE,GACjE,OAAO,YAAI,UACT,MAAM,MACN;EAAK,KAAK;EAAK,QAAQ;EAAK,IAAI,MAAM;MACrC,QAAQ,OAAO,EAA6C;AAc/D;wCACwC,GACxC,OAAO,YAAI,UACT,MAAM,MACN;EAAK,KAAK;EAAK,QAAQ;EAAK,KAAK;MAChC;EAAU,QAAQ;EAAQ,MAAM;IAAW,SAAS,EAatD;AAED;;cAEc,GACd,OAAO,YAAI,QACT,MAAM,MACN;EAAK,KAAK;EAAK,QAAQ;EAAK,IAAI,MAAM;MACrC,QAAQ,UAWV;AAED,+EAA+E,GAC/E,OAAO,YAAI,SAAU;EAAK,KAAK;EAAK,IAAI,MAAM;MAAK,SAGjD;AAEF;;0EAE0E,GAC1E,OAAO,YAAI,YACT,MAAM,MACN,QAAQ,KACR,IAAI,MAAM,KACT,QAAQ,aA6BV"}
@@ -0,0 +1,3 @@
1
+ import type { Runs } from "@yaks/graph/tools";
2
+ /** The implementations of the tools ./vocab.json declares. */ export declare let runs: () => Runs;
3
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAQA,cAAc,IAAI,iCAAsC;AAcxD,4DAA4D,GAC5D,OAAO,YAAI,YAAW,KAsBpB"}
@@ -0,0 +1,3 @@
1
+ import { type Registry } from "@yaks/render";
2
+ /** Connections draw by their public fields, even when they also wear secret. */ export declare let views: Registry;
3
+ //# sourceMappingURL=views.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AAGA,SAAyB,KAAK,QAAQ,4BAAqD;AAuD3F,8EAA8E,GAC9E,OAAO,YAAI,OAAO,SA6BhB"}
@@ -0,0 +1,6 @@
1
+ import type { VocabDoc } from "@yaks/vocab";
2
+ /** `integration`, `connection`, the `uses` relation, and the two tools. */ export declare let connectionsDoc: VocabDoc;
3
+ /** What this package is: its manifest's description, the one place it is
4
+ * written, which a host stamps on each document here. */ export declare let description: string;
5
+ /** Every document this plugin declares. */ export declare let docs: VocabDoc[];
6
+ //# sourceMappingURL=vocab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAKA,cAAc,QAAQ,2BAAgC;AAItD,yEAAyE,GACzE,OAAO,YAAI,gBAAgB,SAA0B;AAErD;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAA6B"}
@@ -0,0 +1,29 @@
1
+ import type { Graph } from "@yaks/graph";
2
+ import type { Vault } from "@yaks/secrets";
3
+ import type { AuthOptions, Callback } from "./authorize.js";
4
+ import { codeFor } from "./signin-mail.js";
5
+ /** A website session for a bot, signed in at `origin` the way a person signs
6
+ * in: it asks for a code, reads it from the letter this bot's graph received,
7
+ * and spends it. No browser and nobody else is asked, so a bot whose session
8
+ * lapsed signs itself in again. */ export declare let botSession: (graph: Pick<Graph, 'read'>, origin: string, address: string, opts?: {
9
+ fetch?: typeof fetch;
10
+ code?: typeof codeFor;
11
+ }) => Promise<string>;
12
+ /** Spend the code sent to this bot's graph, then grant the OAuth request
13
+ * through the page's own q and consent fields. Redirects are never followed
14
+ * with a cookie or code, and the final return must name this flow's redirect. */ export declare let botCallback: (graph: Pick<Graph, 'read'>, url: string, address: string, opts?: {
15
+ fetch?: typeof fetch;
16
+ code?: typeof codeFor;
17
+ session?: string;
18
+ }) => Promise<Callback>;
19
+ /** The discovery and unattended callback seams for the ordinary auth command.
20
+ * A supplied session is for the held-cookie migration, not a terminal option. */ export declare let yaksApp: (h: {
21
+ graph: Graph;
22
+ vault: Vault;
23
+ }, opts?: {
24
+ origin?: string;
25
+ fetch?: typeof fetch;
26
+ code?: typeof codeFor;
27
+ session?: string;
28
+ }) => AuthOptions;
29
+ //# sourceMappingURL=yaks-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaks-app.d.ts","sources":["../yaks-app.ts"],"names":[],"mappings":"AAEA,cAAc,KAAK,2BAAgC;AAMnD,cAAc,KAAK,6BAAkC;AACrD,cAAc,WAAW,EAAE,QAAQ,yBAAwB;AAE3D,SAAS,OAAO,2BAA0B;AAsC1C;;;iCAGiC,GACjC,OAAO,YAAI,aACT,OAAO,KAAK,OAAO,SACnB,QAAQ,MAAM,EACd,SAAS,MAAM,EACf;EAAQ,eAAe;EAAO,cAAc;MAC3C,QAAQ,MAAM,EAsBhB;AAED;;+EAE+E,GAC/E,OAAO,YAAI,cACT,OAAO,KAAK,OAAO,SACnB,KAAK,MAAM,EACX,SAAS,MAAM,EACf;EAAQ,eAAe;EAAO,cAAc;EAAS,UAAU,MAAM;MACpE,QAAQ,UAiCV;AACD;+EAC+E,GAC/E,OAAO,YAAI,UACT;EAAK,OAAO;EAAO,OAAO;GAC1B;EACE,SAAS,MAAM;EACf,eAAe;EACf,cAAc;EACd,UAAU,MAAM;MAEjB,YA0CF"}
package/anthropic.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "anthropic",
3
+ "visitors": "off",
4
+ "title": "Anthropic",
5
+ "tagline": "Claude models, on your own Anthropic API key.",
6
+ "site": "https://www.anthropic.com",
7
+ "hosts": [
8
+ "api.anthropic.com"
9
+ ],
10
+ "instructions": "1. Sign in at [platform.claude.com](https://platform.claude.com) and open [API keys](https://platform.claude.com/settings/keys).\n2. Press **Create Key**, name it, and copy the key it shows (it starts with `sk-ant-`).\n3. Paste it here.",
11
+ "example": "sk-ant-••••••••"
12
+ }
@@ -0,0 +1,69 @@
1
+ // The terminal sign-in command: private input goes directly to authorization
2
+ // and the vault, never through a stored tool call.
3
+ import { person } from "@yaks/cli/config";
4
+ import { yaksApp } from "./yaks-app.js";
5
+ import { authorize } from "./authorize.js";
6
+ import { Refused } from "@yaks/graph/errors";
7
+ import { connect, need, pick } from "./connections.js";
8
+ import { authIO, authorizeCLI } from "./authorize_cli.js";
9
+ import { installGitCredential } from "./git-config.js";
10
+ let git = async (integration, context)=>{
11
+ if (integration != 'yaks.app') return;
12
+ try {
13
+ await installGitCredential();
14
+ } catch (error) {
15
+ if (error.code != 'ENOENT') throw error;
16
+ context.note('Install Git and run yak auth yaks.app to set up Git access.');
17
+ }
18
+ };
19
+ export let auth = async (args, host, context)=>{
20
+ if (args.key) {
21
+ let integration = typeof args.name == 'string' ? args.name : undefined;
22
+ if (!integration) {
23
+ throw new Refused('name the integration for the pasted key');
24
+ }
25
+ let owner = await person(host);
26
+ if (!owner) {
27
+ throw new Refused('a configured person is required to connect a key');
28
+ }
29
+ let as = typeof args.as == 'string' ? args.as : context.as;
30
+ if (integration == 'yaks.app') {
31
+ await yaksApp(host).prepare(integration, as);
32
+ }
33
+ // Whatever could refuse is asked before the paste, so a key pasted is
34
+ // never thrown away. A name no integration holds is kept as a key of its
35
+ // own, sent nowhere until whoever uses it names its hosts.
36
+ let existing = as ? await pick(host.graph.read, owner, integration, as).catch(()=>undefined) : undefined;
37
+ let asked = existing ? undefined : await need(host.graph.read, {
38
+ owner,
39
+ integration
40
+ });
41
+ authIO.say('Paste the key and press Enter (input hidden):');
42
+ let key = await authIO.hidden();
43
+ if (!key) throw new Refused('No key supplied');
44
+ let [b] = existing ? [
45
+ existing
46
+ ] : await host.graph.apply(asked);
47
+ await connect({
48
+ graph: host.graph,
49
+ vault: host.vault
50
+ }, b.entity.eid, {
51
+ key
52
+ }, as);
53
+ await git(integration, context);
54
+ context.out(`${integration} connected.`);
55
+ return 0;
56
+ }
57
+ let connected = await authorizeCLI(authorize({
58
+ graph: host.graph,
59
+ vault: host.vault,
60
+ owner: await person(host)
61
+ }, yaksApp({
62
+ graph: host.graph,
63
+ vault: host.vault
64
+ })), typeof args.name == 'string' ? args.name : undefined, undefined, typeof args.as == 'string' ? args.as : context.as);
65
+ await git(args.name, context);
66
+ context.out(connected);
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Y;IACrD,OAAO,GAAG,CAAC;IACX,IAAI,MAAM,MAAM,OAAO,MAAM;IAC7B,IAAI,CAAC,KAAK,MAAM,IAAI,QAAQ;IAC5B,IAAI,CAAC,EAAE,GAAG,WAAW;MAAC;KAAS,GAAG,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC;IACzD,MAAM,QAAQ;MAAE,OAAO,KAAK,KAAK;MAAE,OAAO,KAAK,KAAK;IAAC,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE;MACpE;IACF,GAAG;IACH,MAAM,IAAI,aAAa;IACvB,QAAQ,GAAG,CAAC,GAAG,YAAY,WAAW,CAAC;IACvC,OAAO;EACT;EACA,IAAI,YAAY,MAAM,aACpB,UAAU;IACR,OAAO,KAAK,KAAK;IACjB,OAAO,KAAK,KAAK;IACjB,OAAO,MAAM,OAAO;EACtB,GAAG,QAAQ;IAAE,OAAO,KAAK,KAAK;IAAE,OAAO,KAAK,KAAK;EAAC,KAClD,OAAO,KAAK,IAAI,IAAI,WAAW,KAAK,IAAI,GAAG,WAC3C,WACA,OAAO,KAAK,EAAE,IAAI,WAAW,KAAK,EAAE,GAAG,QAAQ,EAAE;EAEnD,MAAM,IAAI,KAAK,IAAI,EAAE;EACrB,QAAQ,GAAG,CAAC;EACZ,OAAO;AACT,EAAC"}
@@ -0,0 +1,74 @@
1
+ // The terminal sign-in command: private input goes directly to authorization
2
+ // and the vault, never through a stored tool call.
3
+ import type { CliCommand } from 'jsr:@yaks/cli@0.2.36/host'
4
+ import { person } from '@yaks/cli/config'
5
+ import { yaksApp } from './yaks-app.js'
6
+ import { authorize } from './authorize.js'
7
+ import { Refused } from '@yaks/graph/errors'
8
+ import { connect, need, pick } from './connections.js'
9
+ import { authIO, authorizeCLI } from './authorize_cli.js'
10
+ import { installGitCredential } from './git-config.js'
11
+
12
+ let git = async (
13
+ integration: unknown,
14
+ context: Parameters<CliCommand['run']>[2],
15
+ ) => {
16
+ if (integration != 'yaks.app') return
17
+ try {
18
+ await installGitCredential()
19
+ } catch (error) {
20
+ if ((error as { code?: string }).code != 'ENOENT') throw error
21
+ context.note('Install Git and run yak auth yaks.app to set up Git access.')
22
+ }
23
+ }
24
+
25
+ export let auth: CliCommand['run'] = async (args, host, context) => {
26
+ if (args.key) {
27
+ let integration = typeof args.name == 'string' ? args.name : undefined
28
+ if (!integration) {
29
+ throw new Refused('name the integration for the pasted key')
30
+ }
31
+ let owner = await person(host)
32
+ if (!owner) {
33
+ throw new Refused('a configured person is required to connect a key')
34
+ }
35
+ let as = typeof args.as == 'string' ? args.as : context.as
36
+ if (integration == 'yaks.app') {
37
+ await yaksApp(host).prepare!(integration, as)
38
+ }
39
+ // Whatever could refuse is asked before the paste, so a key pasted is
40
+ // never thrown away. A name no integration holds is kept as a key of its
41
+ // own, sent nowhere until whoever uses it names its hosts.
42
+ let existing = as
43
+ ? await pick(host.graph.read, owner, integration, as).catch(() =>
44
+ undefined
45
+ )
46
+ : undefined
47
+ let asked = existing
48
+ ? undefined
49
+ : await need(host.graph.read, { owner, integration })
50
+ authIO.say('Paste the key and press Enter (input hidden):')
51
+ let key = await authIO.hidden()
52
+ if (!key) throw new Refused('No key supplied')
53
+ let [b] = existing ? [existing] : await host.graph.apply(asked!)
54
+ await connect({ graph: host.graph, vault: host.vault }, b.entity.eid, {
55
+ key,
56
+ }, as)
57
+ await git(integration, context)
58
+ context.out(`${integration} connected.`)
59
+ return 0
60
+ }
61
+ let connected = await authorizeCLI(
62
+ authorize({
63
+ graph: host.graph,
64
+ vault: host.vault,
65
+ owner: await person(host),
66
+ }, yaksApp({ graph: host.graph, vault: host.vault })),
67
+ typeof args.name == 'string' ? args.name : undefined,
68
+ undefined,
69
+ typeof args.as == 'string' ? args.as : context.as,
70
+ )
71
+ await git(args.name, context)
72
+ context.out(connected)
73
+ return 0
74
+ }
package/authorize.js ADDED
@@ -0,0 +1,89 @@
1
+ /** Terminal authorization over integration data. Discovery and unattended
2
+ * callbacks can be supplied by a CLI host without depending on the harness. */ import { Refused } from "@yaks/graph/errors";
3
+ import { install } from "./integrations.js";
4
+ import { REDIRECT, signins } from "./signin.js";
5
+ export let authorize = (h, options = {})=>{
6
+ let signin = signins({
7
+ g: h.graph,
8
+ vault: h.vault,
9
+ fetch: options.fetch
10
+ });
11
+ let targets = new Map();
12
+ let replies = new Map();
13
+ let seed = async ()=>{
14
+ let batch = await install(h.graph.read);
15
+ if (batch.length) await h.graph.apply(batch, {
16
+ trusted: true
17
+ });
18
+ };
19
+ let run = async (action, name, callback, as)=>{
20
+ await seed();
21
+ let integrations = (await h.graph.read('.integration')).map((b)=>b.integration);
22
+ if (action == 'list') {
23
+ let held = integrations.map((i)=>i.title ?? i.name);
24
+ let offered = (options.offers ?? []).filter((name)=>!integrations.some((i)=>i.name == name));
25
+ return {
26
+ servers: [
27
+ ...offered,
28
+ ...held
29
+ ]
30
+ };
31
+ }
32
+ if (!h.owner) {
33
+ throw new Refused('A configured person is required to sign in');
34
+ }
35
+ if (!name) throw new Refused('Name an integration to sign in');
36
+ let target = targets.get(name);
37
+ if (action == 'begin') {
38
+ target = await options.prepare?.(name, as);
39
+ if (!target) {
40
+ let found = integrations.find((i)=>i.name == name || i.title == name);
41
+ if (found) target = {
42
+ integration: found.name
43
+ };
44
+ }
45
+ if (!target) throw new Refused('Unknown integration');
46
+ target = {
47
+ ...target,
48
+ redirect: target.redirect ?? (target.integration == 'openai' ? 'http://127.0.0.1:1455/auth/callback' : REDIRECT)
49
+ };
50
+ targets.set(name, target);
51
+ let begun = await signin.begin(h.owner, target.integration, target.redirect);
52
+ let automatic = await options.callback?.(target, begun.url, as);
53
+ if (automatic) replies.set(name, automatic);
54
+ return begun;
55
+ }
56
+ if (action == 'cancel') {
57
+ signin.cancel(h.owner);
58
+ targets.clear();
59
+ replies.clear();
60
+ return {
61
+ message: 'Authorization cancelled'
62
+ };
63
+ }
64
+ if (!target) {
65
+ throw new Refused('Authorization expired or not started; begin again');
66
+ }
67
+ let returned = replies.get(name) ?? (typeof callback == 'string' ? {
68
+ callback
69
+ } : callback);
70
+ if (!returned) throw new Refused('Paste the complete return URL');
71
+ await signin.complete(h.owner, target.integration, returned.callback, returned.session);
72
+ targets.delete(name);
73
+ replies.delete(name);
74
+ return {
75
+ message: `${integrations.find((i)=>i.name == target.integration)?.title ?? target.integration} connected.`
76
+ };
77
+ };
78
+ return {
79
+ run,
80
+ /** A bot callback is already held privately and needs no terminal paste. */ returned: (name)=>replies.has(name),
81
+ close: ()=>{
82
+ signin.cancel();
83
+ targets.clear();
84
+ replies.clear();
85
+ return Promise.resolve();
86
+ }
87
+ };
88
+ };
89
+ //# sourceMappingURL=authorize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.js","sources":["./authorize.ts"],"names":[],"mappings":"AAAA;6EAC6E,GAE7E,SAAS,OAAO,kCAAuC;AAEvD,SAAS,OAAO,4BAA6C;AAC7D,SAAS,QAAQ,EAAE,OAAO,sBAAqB;AAoC/C,OAAO,IAAI,YAAY,CACrB,GACA,UAAuB,CAAC,CAAC;EAEzB,IAAI,SAAS,QAAQ;IAAE,GAAG,EAAE,KAAK;IAAE,OAAO,EAAE,KAAK;IAAE,OAAO,QAAQ,KAAK;EAAC;EACxE,IAAI,UAAU,IAAI;EAClB,IAAI,UAAU,IAAI;EAClB,IAAI,OAAO;IACT,IAAI,QAAQ,MAAM,QAAQ,EAAE,KAAK,CAAC,IAAI;IACtC,IAAI,MAAM,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;MAAE,SAAS;IAAK;EAC/D;EACA,IAAI,MAAM,OACR,QACA,MACA,UACA;IAEA,MAAM;IACN,IAAI,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,IAC3D,EAAE,WAAW;IAEf,IAAI,UAAU,QAAQ;MACpB,IAAI,OAAO,aAAa,GAAG,CAAC,CAAC,IAAM,EAAE,KAAK,IAAI,EAAE,IAAI;MACpD,IAAI,UAA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E;IAAS,IAAI,QAAQ;IACxD,IAAI,CAAC,UAAU,MAAM,IAAI,QAAQ;IACjC,MAAM,OAAO,QAAQ,CACnB,EAAE,KAAK,EACP,OAAO,WAAW,EAClB,SAAS,QAAQ,EACjB,SAAS,OAAO;IAElB,QAAQ,MAAM,CAAC;IACf,QAAQ,MAAM,CAAC;IACf,OAAO;MACL,SAAS,GACP,aAAa,IAAI,CAAC,CAAC,IAAM,EAAE,IAAI,IAAI,OAAQ,WAAW,GAAG,SACvD,OAAO,WAAW,CACrB,WAAW,CAAC;IACf;EACF;EACA,OAAO;IACL;IACA,0EAA0E,GAC1E,UAAU,CAAC,OAAiB,QAAQ,GAAG,CAAC;IACxC,OAAO;MACL,OAAO,MAAM;MACb,QAAQ,KAAK;MACb,QAAQ,KAAK;MACb,OAAO,QAAQ,OAAO;IACxB;EACF;AACF,EAAC"}
package/authorize.ts ADDED
@@ -0,0 +1,138 @@
1
+ /** Terminal authorization over integration data. Discovery and unattended
2
+ * callbacks can be supplied by a CLI host without depending on the harness. */
3
+ import type { Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
4
+ import { Refused } from '@yaks/graph/errors'
5
+ import type { Vault } from 'jsr:@yaks/secrets@0.2.36'
6
+ import { install, type Integration } from './integrations.js'
7
+ import { REDIRECT, signins } from './signin.js'
8
+
9
+ export type AuthAction = 'list' | 'begin' | 'complete' | 'cancel'
10
+ export type Callback = { callback: string; session?: string }
11
+ export type AuthReply = {
12
+ servers?: string[]
13
+ message?: string
14
+ url?: string
15
+ redirectUrl?: string
16
+ }
17
+ export type Authorization = {
18
+ run: (
19
+ action: AuthAction,
20
+ name?: string,
21
+ callback?: string | Callback,
22
+ as?: string,
23
+ ) => Promise<AuthReply>
24
+ returned?: (name: string) => boolean
25
+ close: () => Promise<void>
26
+ }
27
+ export type AuthTarget = { integration: string; redirect?: string }
28
+ export type AuthOptions = {
29
+ /** Transport for discovery, token exchange and account reads. */
30
+ fetch?: typeof fetch
31
+ /** The integrations `prepare` can sign in to before the graph holds them,
32
+ * listed beside the ones it does. */
33
+ offers?: string[]
34
+ /** Discover/register an unknown integration, returning its name and redirect. */
35
+ prepare?: (name: string, as?: string) => Promise<AuthTarget | undefined>
36
+ /** An unattended sign-in returns its private callback and optional website session. */
37
+ callback?: (
38
+ target: AuthTarget,
39
+ url: string,
40
+ as?: string,
41
+ ) => Promise<Callback | undefined>
42
+ }
43
+ export let authorize = (
44
+ h: { graph: Graph; vault: Vault; owner?: Eid },
45
+ options: AuthOptions = {},
46
+ ): Authorization & { returned: (name: string) => boolean } => {
47
+ let signin = signins({ g: h.graph, vault: h.vault, fetch: options.fetch })
48
+ let targets = new Map<string, AuthTarget>()
49
+ let replies = new Map<string, Callback>()
50
+ let seed = async () => {
51
+ let batch = await install(h.graph.read)
52
+ if (batch.length) await h.graph.apply(batch, { trusted: true })
53
+ }
54
+ let run = async (
55
+ action: AuthAction,
56
+ name?: string,
57
+ callback?: string | Callback,
58
+ as?: string,
59
+ ): Promise<AuthReply> => {
60
+ await seed()
61
+ let integrations = (await h.graph.read('.integration')).map((b) =>
62
+ b.integration as Integration
63
+ )
64
+ if (action == 'list') {
65
+ let held = integrations.map((i) => i.title ?? i.name)
66
+ let offered = (options.offers ?? []).filter((name) =>
67
+ !integrations.some((i) => i.name == name)
68
+ )
69
+ return { servers: [...offered, ...held] }
70
+ }
71
+ if (!h.owner) {
72
+ throw new Refused('A configured person is required to sign in')
73
+ }
74
+ if (!name) throw new Refused('Name an integration to sign in')
75
+ let target = targets.get(name)
76
+ if (action == 'begin') {
77
+ target = await options.prepare?.(name, as)
78
+ if (!target) {
79
+ let found = integrations.find((i) => i.name == name || i.title == name)
80
+ if (found) target = { integration: found.name }
81
+ }
82
+ if (!target) throw new Refused('Unknown integration')
83
+ target = {
84
+ ...target,
85
+ redirect: target.redirect ??
86
+ (target.integration == 'openai'
87
+ ? 'http://127.0.0.1:1455/auth/callback'
88
+ : REDIRECT),
89
+ }
90
+ targets.set(name, target)
91
+ let begun = await signin.begin(
92
+ h.owner,
93
+ target.integration,
94
+ target.redirect,
95
+ )
96
+ let automatic = await options.callback?.(target, begun.url, as)
97
+ if (automatic) replies.set(name, automatic)
98
+ return begun
99
+ }
100
+ if (action == 'cancel') {
101
+ signin.cancel(h.owner)
102
+ targets.clear()
103
+ replies.clear()
104
+ return { message: 'Authorization cancelled' }
105
+ }
106
+ if (!target) {
107
+ throw new Refused('Authorization expired or not started; begin again')
108
+ }
109
+ let returned = replies.get(name) ??
110
+ (typeof callback == 'string' ? { callback } : callback)
111
+ if (!returned) throw new Refused('Paste the complete return URL')
112
+ await signin.complete(
113
+ h.owner,
114
+ target.integration,
115
+ returned.callback,
116
+ returned.session,
117
+ )
118
+ targets.delete(name)
119
+ replies.delete(name)
120
+ return {
121
+ message: `${
122
+ integrations.find((i) => i.name == target!.integration)?.title ??
123
+ target.integration
124
+ } connected.`,
125
+ }
126
+ }
127
+ return {
128
+ run,
129
+ /** A bot callback is already held privately and needs no terminal paste. */
130
+ returned: (name: string) => replies.has(name),
131
+ close: () => {
132
+ signin.cancel()
133
+ targets.clear()
134
+ replies.clear()
135
+ return Promise.resolve()
136
+ },
137
+ }
138
+ }