@celljs/ta-host 4.5.0 → 4.6.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.
- package/README.md +31 -8
- package/cell.schema.json +18 -0
- package/cell.yml +4 -0
- package/esm/node/auth-server-impl.d.ts +61 -0
- package/esm/node/auth-server-impl.js +247 -0
- package/esm/node/auth-server-impl.js.map +1 -0
- package/esm/node/client-tool-broker.d.ts +35 -0
- package/esm/node/client-tool-broker.js +82 -0
- package/esm/node/client-tool-broker.js.map +1 -0
- package/esm/node/exec-environment-factory.d.ts +17 -0
- package/esm/node/exec-environment-factory.js +58 -0
- package/esm/node/exec-environment-factory.js.map +1 -0
- package/esm/node/extension-data-notifier.d.ts +41 -0
- package/esm/node/extension-data-notifier.js +119 -0
- package/esm/node/extension-data-notifier.js.map +1 -0
- package/esm/node/extension-data.d.ts +45 -0
- package/esm/node/extension-data.js +181 -0
- package/esm/node/extension-data.js.map +1 -0
- package/esm/node/host-protocol.d.ts +29 -1
- package/esm/node/host-protocol.js +2 -0
- package/esm/node/host-protocol.js.map +1 -1
- package/esm/node/index.d.ts +24 -1
- package/esm/node/index.js +24 -1
- package/esm/node/index.js.map +1 -1
- package/esm/node/package-host-extension.d.ts +9 -0
- package/esm/node/package-host-extension.js +18 -0
- package/esm/node/package-host-extension.js.map +1 -0
- package/esm/node/package-hosts.d.ts +44 -0
- package/esm/node/package-hosts.js +167 -0
- package/esm/node/package-hosts.js.map +1 -0
- package/esm/node/package-server-impl.d.ts +25 -0
- package/esm/node/package-server-impl.js +94 -0
- package/esm/node/package-server-impl.js.map +1 -0
- package/esm/node/package-switch.d.ts +29 -0
- package/esm/node/package-switch.js +68 -0
- package/esm/node/package-switch.js.map +1 -0
- package/esm/node/relay-bridge.d.ts +34 -0
- package/esm/node/relay-bridge.js +105 -0
- package/esm/node/relay-bridge.js.map +1 -0
- package/esm/node/session-info-util.d.ts +16 -0
- package/esm/node/session-info-util.js +49 -0
- package/esm/node/session-info-util.js.map +1 -0
- package/esm/node/session-storage/file-session-storage.d.ts +27 -0
- package/esm/node/session-storage/file-session-storage.js +139 -0
- package/esm/node/session-storage/file-session-storage.js.map +1 -0
- package/esm/node/session-storage/index.d.ts +3 -0
- package/esm/node/session-storage/index.js +4 -0
- package/esm/node/session-storage/index.js.map +1 -0
- package/esm/node/session-storage/session-storage-protocol.d.ts +57 -0
- package/esm/node/session-storage/session-storage-protocol.js +40 -0
- package/esm/node/session-storage/session-storage-protocol.js.map +1 -0
- package/esm/node/session-storage/stored-session.d.ts +46 -0
- package/esm/node/session-storage/stored-session.js +116 -0
- package/esm/node/session-storage/stored-session.js.map +1 -0
- package/esm/node/settings-server-impl.d.ts +11 -0
- package/esm/node/settings-server-impl.js +45 -0
- package/esm/node/settings-server-impl.js.map +1 -0
- package/esm/node/settings-store.d.ts +56 -0
- package/esm/node/settings-store.js +306 -0
- package/esm/node/settings-store.js.map +1 -0
- package/esm/node/ta-access.d.ts +19 -2
- package/esm/node/ta-access.js +64 -7
- package/esm/node/ta-access.js.map +1 -1
- package/esm/node/ta-errors.d.ts +3 -1
- package/esm/node/ta-errors.js +17 -1
- package/esm/node/ta-errors.js.map +1 -1
- package/esm/node/ta-server-impl.d.ts +17 -5
- package/esm/node/ta-server-impl.js +70 -13
- package/esm/node/ta-server-impl.js.map +1 -1
- package/esm/node/ta-session-factory.d.ts +2 -0
- package/esm/node/ta-session-factory.js +25 -11
- package/esm/node/ta-session-factory.js.map +1 -1
- package/esm/node/ta-session.d.ts +9 -1
- package/esm/node/ta-session.js +26 -2
- package/esm/node/ta-session.js.map +1 -1
- package/esm/node/terminal-protocol.d.ts +18 -0
- package/esm/node/terminal-protocol.js +2 -0
- package/esm/node/terminal-protocol.js.map +1 -0
- package/esm/node/terminal-service.d.ts +59 -0
- package/esm/node/terminal-service.js +240 -0
- package/esm/node/terminal-service.js.map +1 -0
- package/esm/node/terminal-util.d.ts +62 -0
- package/esm/node/terminal-util.js +153 -0
- package/esm/node/terminal-util.js.map +1 -0
- package/esm/node/web-extension-catalog.d.ts +38 -0
- package/esm/node/web-extension-catalog.js +160 -0
- package/esm/node/web-extension-catalog.js.map +1 -0
- package/esm/node/web-extension-util.d.ts +21 -0
- package/esm/node/web-extension-util.js +123 -0
- package/esm/node/web-extension-util.js.map +1 -0
- package/esm/node/working-directory.d.ts +13 -0
- package/esm/node/working-directory.js +40 -0
- package/esm/node/working-directory.js.map +1 -0
- package/esm/node/workspace-files.d.ts +47 -0
- package/esm/node/workspace-files.js +265 -0
- package/esm/node/workspace-files.js.map +1 -0
- package/esm/node/workspace-protocol.d.ts +20 -0
- package/esm/node/workspace-protocol.js +3 -0
- package/esm/node/workspace-protocol.js.map +1 -0
- package/esm/node/workspace-server-impl.d.ts +27 -0
- package/esm/node/workspace-server-impl.js +88 -0
- package/esm/node/workspace-server-impl.js.map +1 -0
- package/esm/node/workspace-service.d.ts +31 -0
- package/esm/node/workspace-service.js +209 -0
- package/esm/node/workspace-service.js.map +1 -0
- package/esm/node/workspace-util.d.ts +29 -0
- package/esm/node/workspace-util.js +104 -0
- package/esm/node/workspace-util.js.map +1 -0
- package/lib/node/auth-server-impl.d.ts +62 -0
- package/lib/node/auth-server-impl.d.ts.map +1 -0
- package/lib/node/auth-server-impl.js +250 -0
- package/lib/node/auth-server-impl.js.map +1 -0
- package/lib/node/auth-server-impl.spec.d.ts +2 -0
- package/lib/node/auth-server-impl.spec.d.ts.map +1 -0
- package/lib/node/auth-server-impl.spec.js +47 -0
- package/lib/node/auth-server-impl.spec.js.map +1 -0
- package/lib/node/client-tool-broker.d.ts +36 -0
- package/lib/node/client-tool-broker.d.ts.map +1 -0
- package/lib/node/client-tool-broker.js +86 -0
- package/lib/node/client-tool-broker.js.map +1 -0
- package/lib/node/client-tool-broker.spec.d.ts +2 -0
- package/lib/node/client-tool-broker.spec.d.ts.map +1 -0
- package/lib/node/client-tool-broker.spec.js +49 -0
- package/lib/node/client-tool-broker.spec.js.map +1 -0
- package/lib/node/exec-environment-factory.d.ts +18 -0
- package/lib/node/exec-environment-factory.d.ts.map +1 -0
- package/lib/node/exec-environment-factory.js +61 -0
- package/lib/node/exec-environment-factory.js.map +1 -0
- package/lib/node/extension-data-notifier.d.ts +42 -0
- package/lib/node/extension-data-notifier.d.ts.map +1 -0
- package/lib/node/extension-data-notifier.js +123 -0
- package/lib/node/extension-data-notifier.js.map +1 -0
- package/lib/node/extension-data-notifier.spec.d.ts +2 -0
- package/lib/node/extension-data-notifier.spec.d.ts.map +1 -0
- package/lib/node/extension-data-notifier.spec.js +35 -0
- package/lib/node/extension-data-notifier.spec.js.map +1 -0
- package/lib/node/extension-data.d.ts +46 -0
- package/lib/node/extension-data.d.ts.map +1 -0
- package/lib/node/extension-data.js +184 -0
- package/lib/node/extension-data.js.map +1 -0
- package/lib/node/extension-data.spec.d.ts +2 -0
- package/lib/node/extension-data.spec.d.ts.map +1 -0
- package/lib/node/extension-data.spec.js +99 -0
- package/lib/node/extension-data.spec.js.map +1 -0
- package/lib/node/host-protocol.d.ts +29 -1
- package/lib/node/host-protocol.d.ts.map +1 -1
- package/lib/node/host-protocol.js +3 -1
- package/lib/node/host-protocol.js.map +1 -1
- package/lib/node/index.d.ts +24 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +24 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/package-host-extension.d.ts +10 -0
- package/lib/node/package-host-extension.d.ts.map +1 -0
- package/lib/node/package-host-extension.js +22 -0
- package/lib/node/package-host-extension.js.map +1 -0
- package/lib/node/package-hosts.d.ts +45 -0
- package/lib/node/package-hosts.d.ts.map +1 -0
- package/lib/node/package-hosts.js +170 -0
- package/lib/node/package-hosts.js.map +1 -0
- package/lib/node/package-hosts.spec.d.ts +2 -0
- package/lib/node/package-hosts.spec.d.ts.map +1 -0
- package/lib/node/package-hosts.spec.js +53 -0
- package/lib/node/package-hosts.spec.js.map +1 -0
- package/lib/node/package-server-impl.d.ts +26 -0
- package/lib/node/package-server-impl.d.ts.map +1 -0
- package/lib/node/package-server-impl.js +97 -0
- package/lib/node/package-server-impl.js.map +1 -0
- package/lib/node/package-switch.d.ts +30 -0
- package/lib/node/package-switch.d.ts.map +1 -0
- package/lib/node/package-switch.js +71 -0
- package/lib/node/package-switch.js.map +1 -0
- package/lib/node/relay-bridge.d.ts +35 -0
- package/lib/node/relay-bridge.d.ts.map +1 -0
- package/lib/node/relay-bridge.js +108 -0
- package/lib/node/relay-bridge.js.map +1 -0
- package/lib/node/session-info-util.d.ts +17 -0
- package/lib/node/session-info-util.d.ts.map +1 -0
- package/lib/node/session-info-util.js +52 -0
- package/lib/node/session-info-util.js.map +1 -0
- package/lib/node/session-info-util.spec.d.ts +2 -0
- package/lib/node/session-info-util.spec.d.ts.map +1 -0
- package/lib/node/session-info-util.spec.js +22 -0
- package/lib/node/session-info-util.spec.js.map +1 -0
- package/lib/node/session-storage/file-session-storage.d.ts +28 -0
- package/lib/node/session-storage/file-session-storage.d.ts.map +1 -0
- package/lib/node/session-storage/file-session-storage.js +143 -0
- package/lib/node/session-storage/file-session-storage.js.map +1 -0
- package/lib/node/session-storage/file-session-storage.spec.d.ts +2 -0
- package/lib/node/session-storage/file-session-storage.spec.d.ts.map +1 -0
- package/lib/node/session-storage/file-session-storage.spec.js +70 -0
- package/lib/node/session-storage/file-session-storage.spec.js.map +1 -0
- package/lib/node/session-storage/index.d.ts +4 -0
- package/lib/node/session-storage/index.d.ts.map +1 -0
- package/lib/node/session-storage/index.js +20 -0
- package/lib/node/session-storage/index.js.map +1 -0
- package/lib/node/session-storage/session-storage-protocol.d.ts +58 -0
- package/lib/node/session-storage/session-storage-protocol.d.ts.map +1 -0
- package/lib/node/session-storage/session-storage-protocol.js +45 -0
- package/lib/node/session-storage/session-storage-protocol.js.map +1 -0
- package/lib/node/session-storage/stored-session.d.ts +47 -0
- package/lib/node/session-storage/stored-session.d.ts.map +1 -0
- package/lib/node/session-storage/stored-session.js +120 -0
- package/lib/node/session-storage/stored-session.js.map +1 -0
- package/lib/node/session-storage/stored-session.spec.d.ts +2 -0
- package/lib/node/session-storage/stored-session.spec.d.ts.map +1 -0
- package/lib/node/session-storage/stored-session.spec.js +73 -0
- package/lib/node/session-storage/stored-session.spec.js.map +1 -0
- package/lib/node/settings-server-impl.d.ts +12 -0
- package/lib/node/settings-server-impl.d.ts.map +1 -0
- package/lib/node/settings-server-impl.js +48 -0
- package/lib/node/settings-server-impl.js.map +1 -0
- package/lib/node/settings-store.d.ts +57 -0
- package/lib/node/settings-store.d.ts.map +1 -0
- package/lib/node/settings-store.js +309 -0
- package/lib/node/settings-store.js.map +1 -0
- package/lib/node/settings-store.spec.d.ts +2 -0
- package/lib/node/settings-store.spec.d.ts.map +1 -0
- package/lib/node/settings-store.spec.js +145 -0
- package/lib/node/settings-store.spec.js.map +1 -0
- package/lib/node/ta-access.d.ts +19 -2
- package/lib/node/ta-access.d.ts.map +1 -1
- package/lib/node/ta-access.js +66 -9
- package/lib/node/ta-access.js.map +1 -1
- package/lib/node/ta-access.spec.js +8 -0
- package/lib/node/ta-access.spec.js.map +1 -1
- package/lib/node/ta-errors.d.ts +3 -1
- package/lib/node/ta-errors.d.ts.map +1 -1
- package/lib/node/ta-errors.js +17 -1
- package/lib/node/ta-errors.js.map +1 -1
- package/lib/node/ta-errors.spec.d.ts +2 -0
- package/lib/node/ta-errors.spec.d.ts.map +1 -0
- package/lib/node/ta-errors.spec.js +25 -0
- package/lib/node/ta-errors.spec.js.map +1 -0
- package/lib/node/ta-server-impl.d.ts +17 -5
- package/lib/node/ta-server-impl.d.ts.map +1 -1
- package/lib/node/ta-server-impl.js +70 -13
- package/lib/node/ta-server-impl.js.map +1 -1
- package/lib/node/ta-session-factory.d.ts +2 -0
- package/lib/node/ta-session-factory.d.ts.map +1 -1
- package/lib/node/ta-session-factory.js +24 -10
- package/lib/node/ta-session-factory.js.map +1 -1
- package/lib/node/ta-session.d.ts +9 -1
- package/lib/node/ta-session.d.ts.map +1 -1
- package/lib/node/ta-session.js +26 -2
- package/lib/node/ta-session.js.map +1 -1
- package/lib/node/terminal-protocol.d.ts +19 -0
- package/lib/node/terminal-protocol.d.ts.map +1 -0
- package/lib/node/terminal-protocol.js +5 -0
- package/lib/node/terminal-protocol.js.map +1 -0
- package/lib/node/terminal-service.d.ts +60 -0
- package/lib/node/terminal-service.d.ts.map +1 -0
- package/lib/node/terminal-service.js +241 -0
- package/lib/node/terminal-service.js.map +1 -0
- package/lib/node/terminal-service.spec.d.ts +2 -0
- package/lib/node/terminal-service.spec.d.ts.map +1 -0
- package/lib/node/terminal-service.spec.js +79 -0
- package/lib/node/terminal-service.spec.js.map +1 -0
- package/lib/node/terminal-util.d.ts +63 -0
- package/lib/node/terminal-util.d.ts.map +1 -0
- package/lib/node/terminal-util.js +158 -0
- package/lib/node/terminal-util.js.map +1 -0
- package/lib/node/terminal-util.spec.d.ts +2 -0
- package/lib/node/terminal-util.spec.d.ts.map +1 -0
- package/lib/node/terminal-util.spec.js +71 -0
- package/lib/node/terminal-util.spec.js.map +1 -0
- package/lib/node/web-extension-catalog.d.ts +39 -0
- package/lib/node/web-extension-catalog.d.ts.map +1 -0
- package/lib/node/web-extension-catalog.js +163 -0
- package/lib/node/web-extension-catalog.js.map +1 -0
- package/lib/node/web-extension-catalog.spec.d.ts +2 -0
- package/lib/node/web-extension-catalog.spec.d.ts.map +1 -0
- package/lib/node/web-extension-catalog.spec.js +157 -0
- package/lib/node/web-extension-catalog.spec.js.map +1 -0
- package/lib/node/web-extension-util.d.ts +22 -0
- package/lib/node/web-extension-util.d.ts.map +1 -0
- package/lib/node/web-extension-util.js +126 -0
- package/lib/node/web-extension-util.js.map +1 -0
- package/lib/node/working-directory.d.ts +14 -0
- package/lib/node/working-directory.d.ts.map +1 -0
- package/lib/node/working-directory.js +43 -0
- package/lib/node/working-directory.js.map +1 -0
- package/lib/node/workspace-files.d.ts +48 -0
- package/lib/node/workspace-files.d.ts.map +1 -0
- package/lib/node/workspace-files.js +268 -0
- package/lib/node/workspace-files.js.map +1 -0
- package/lib/node/workspace-files.spec.d.ts +2 -0
- package/lib/node/workspace-files.spec.d.ts.map +1 -0
- package/lib/node/workspace-files.spec.js +133 -0
- package/lib/node/workspace-files.spec.js.map +1 -0
- package/lib/node/workspace-protocol.d.ts +21 -0
- package/lib/node/workspace-protocol.d.ts.map +1 -0
- package/lib/node/workspace-protocol.js +6 -0
- package/lib/node/workspace-protocol.js.map +1 -0
- package/lib/node/workspace-server-impl.d.ts +28 -0
- package/lib/node/workspace-server-impl.d.ts.map +1 -0
- package/lib/node/workspace-server-impl.js +91 -0
- package/lib/node/workspace-server-impl.js.map +1 -0
- package/lib/node/workspace-service.d.ts +32 -0
- package/lib/node/workspace-service.d.ts.map +1 -0
- package/lib/node/workspace-service.js +212 -0
- package/lib/node/workspace-service.js.map +1 -0
- package/lib/node/workspace-service.spec.d.ts +2 -0
- package/lib/node/workspace-service.spec.d.ts.map +1 -0
- package/lib/node/workspace-service.spec.js +104 -0
- package/lib/node/workspace-service.spec.js.map +1 -0
- package/lib/node/workspace-util.d.ts +30 -0
- package/lib/node/workspace-util.d.ts.map +1 -0
- package/lib/node/workspace-util.js +107 -0
- package/lib/node/workspace-util.js.map +1 -0
- package/lib/node/workspace-util.spec.d.ts +2 -0
- package/lib/node/workspace-util.spec.d.ts.map +1 -0
- package/lib/node/workspace-util.spec.js +44 -0
- package/lib/node/workspace-util.spec.js.map +1 -0
- package/package.json +14 -9
- package/src/node/auth-server-impl.spec.ts +49 -0
- package/src/node/auth-server-impl.ts +252 -0
- package/src/node/client-tool-broker.spec.ts +53 -0
- package/src/node/client-tool-broker.ts +106 -0
- package/src/node/exec-environment-factory.ts +46 -0
- package/src/node/extension-data-notifier.spec.ts +34 -0
- package/src/node/extension-data-notifier.ts +124 -0
- package/src/node/extension-data.spec.ts +105 -0
- package/src/node/extension-data.ts +180 -0
- package/src/node/host-protocol.ts +31 -1
- package/src/node/index.ts +24 -1
- package/src/node/package-host-extension.ts +20 -0
- package/src/node/package-hosts.spec.ts +54 -0
- package/src/node/package-hosts.ts +174 -0
- package/src/node/package-server-impl.ts +87 -0
- package/src/node/package-switch.ts +80 -0
- package/src/node/relay-bridge.ts +94 -0
- package/src/node/session-info-util.spec.ts +23 -0
- package/src/node/session-info-util.ts +55 -0
- package/src/node/session-storage/file-session-storage.spec.ts +72 -0
- package/src/node/session-storage/file-session-storage.ts +145 -0
- package/src/node/session-storage/index.ts +3 -0
- package/src/node/session-storage/session-storage-protocol.ts +81 -0
- package/src/node/session-storage/stored-session.spec.ts +80 -0
- package/src/node/session-storage/stored-session.ts +149 -0
- package/src/node/settings-server-impl.ts +33 -0
- package/src/node/settings-store.spec.ts +155 -0
- package/src/node/settings-store.ts +308 -0
- package/src/node/ta-access.spec.ts +9 -0
- package/src/node/ta-access.ts +65 -7
- package/src/node/ta-errors.spec.ts +25 -0
- package/src/node/ta-errors.ts +21 -1
- package/src/node/ta-server-impl.ts +75 -12
- package/src/node/ta-session-factory.ts +21 -7
- package/src/node/ta-session.ts +43 -3
- package/src/node/terminal-protocol.ts +18 -0
- package/src/node/terminal-service.spec.ts +84 -0
- package/src/node/terminal-service.ts +259 -0
- package/src/node/terminal-util.spec.ts +78 -0
- package/src/node/terminal-util.ts +166 -0
- package/src/node/web-extension-catalog.spec.ts +172 -0
- package/src/node/web-extension-catalog.ts +172 -0
- package/src/node/web-extension-util.ts +144 -0
- package/src/node/working-directory.ts +38 -0
- package/src/node/workspace-files.spec.ts +145 -0
- package/src/node/workspace-files.ts +256 -0
- package/src/node/workspace-protocol.ts +22 -0
- package/src/node/workspace-server-impl.ts +90 -0
- package/src/node/workspace-service.spec.ts +113 -0
- package/src/node/workspace-service.ts +223 -0
- package/src/node/workspace-util.spec.ts +47 -0
- package/src/node/workspace-util.ts +103 -0
- package/esm/node/local-exec-environment-factory.d.ts +0 -4
- package/esm/node/local-exec-environment-factory.js +0 -18
- package/esm/node/local-exec-environment-factory.js.map +0 -1
- package/lib/node/local-exec-environment-factory.d.ts +0 -5
- package/lib/node/local-exec-environment-factory.d.ts.map +0 -1
- package/lib/node/local-exec-environment-factory.js +0 -21
- package/lib/node/local-exec-environment-factory.js.map +0 -1
- package/src/node/local-exec-environment-factory.ts +0 -9
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TaAuthServerImpl = exports.AuthServerUtil = void 0;
|
|
13
|
+
const node_crypto_1 = require("node:crypto");
|
|
14
|
+
const ai_coding_agent_1 = require("@celljs/ai-coding-agent");
|
|
15
|
+
const core_1 = require("@celljs/core");
|
|
16
|
+
const rpc_1 = require("@celljs/rpc");
|
|
17
|
+
const node_1 = require("@celljs/rpc/lib/node");
|
|
18
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
19
|
+
const host_protocol_1 = require("./host-protocol");
|
|
20
|
+
const ta_errors_1 = require("./ta-errors");
|
|
21
|
+
/** pi's message when a sign-in is cancelled; the client says so in its own words. */
|
|
22
|
+
const CANCELLED = 'Login cancelled';
|
|
23
|
+
/** A sign-in that a connection started, and the prompts it waits on. */
|
|
24
|
+
class Login {
|
|
25
|
+
constructor(id, connection) {
|
|
26
|
+
this.id = id;
|
|
27
|
+
this.connection = connection;
|
|
28
|
+
this.abort = new AbortController();
|
|
29
|
+
this.waiting = new Map();
|
|
30
|
+
this.nextPrompt = 0;
|
|
31
|
+
}
|
|
32
|
+
send(event) {
|
|
33
|
+
this.connection
|
|
34
|
+
.client(ta_protocol_1.TaClient)
|
|
35
|
+
.onAuthEvent(this.id, event)
|
|
36
|
+
.catch(() => undefined);
|
|
37
|
+
}
|
|
38
|
+
/** Asks the client; an answer or a cancellation settles it, as does pi when the step resolves otherwise. */
|
|
39
|
+
ask(prompt) {
|
|
40
|
+
const promptId = `p${++this.nextPrompt}`;
|
|
41
|
+
const { signal, ...rest } = prompt;
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const close = () => {
|
|
44
|
+
this.waiting.delete(promptId);
|
|
45
|
+
this.send({ type: 'prompt_closed', promptId });
|
|
46
|
+
reject(new Error(CANCELLED));
|
|
47
|
+
};
|
|
48
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
49
|
+
close();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', close, { once: true });
|
|
53
|
+
this.waiting.set(promptId, {
|
|
54
|
+
resolve: value => {
|
|
55
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', close);
|
|
56
|
+
resolve(value);
|
|
57
|
+
},
|
|
58
|
+
reject: error => {
|
|
59
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', close);
|
|
60
|
+
reject(error);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
this.send({ type: 'prompt', promptId, prompt: rest });
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
cancel() {
|
|
67
|
+
this.abort.abort();
|
|
68
|
+
for (const waiting of this.waiting.values()) {
|
|
69
|
+
waiting.reject(new Error(CANCELLED));
|
|
70
|
+
}
|
|
71
|
+
this.waiting.clear();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
var AuthServerUtil;
|
|
75
|
+
(function (AuthServerUtil) {
|
|
76
|
+
/** The ways to sign in, as pi's `/login` lists them, by name. */
|
|
77
|
+
function providers(runtime, stored) {
|
|
78
|
+
var _a;
|
|
79
|
+
var _b;
|
|
80
|
+
const list = [];
|
|
81
|
+
for (const provider of runtime.getProviders()) {
|
|
82
|
+
const status = runtime.getProviderAuthStatus(provider.id);
|
|
83
|
+
const configured = status.configured
|
|
84
|
+
? { type: (runtime.isUsingOAuth(provider.id) ? 'oauth' : 'api_key'), source: (_b = status.label) !== null && _b !== void 0 ? _b : status.source }
|
|
85
|
+
: undefined;
|
|
86
|
+
const base = {
|
|
87
|
+
id: provider.id,
|
|
88
|
+
name: provider.name,
|
|
89
|
+
configured,
|
|
90
|
+
stored: stored.has(provider.id),
|
|
91
|
+
subscription: ((_a = provider.auth.oauth) === null || _a === void 0 ? void 0 : _a.isSubscription) === true,
|
|
92
|
+
};
|
|
93
|
+
if (provider.auth.oauth) {
|
|
94
|
+
list.push({ ...base, type: 'oauth', interactive: true });
|
|
95
|
+
}
|
|
96
|
+
if (provider.auth.apiKey) {
|
|
97
|
+
list.push({ ...base, type: 'api_key', interactive: typeof provider.auth.apiKey.login === 'function' });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return list.sort((a, b) => a.name.localeCompare(b.name));
|
|
101
|
+
}
|
|
102
|
+
AuthServerUtil.providers = providers;
|
|
103
|
+
/** pi's AuthEvent as the protocol has it: plain data, and only what a client shows. */
|
|
104
|
+
function event(event) {
|
|
105
|
+
var _a;
|
|
106
|
+
switch (event.type) {
|
|
107
|
+
case 'auth_url':
|
|
108
|
+
return { type: 'auth_url', url: event.url, instructions: event.instructions };
|
|
109
|
+
case 'device_code':
|
|
110
|
+
return { type: 'device_code', userCode: event.userCode, verificationUri: event.verificationUri, expiresInSeconds: event.expiresInSeconds };
|
|
111
|
+
case 'info':
|
|
112
|
+
return { type: 'info', message: event.message, links: (_a = event.links) === null || _a === void 0 ? void 0 : _a.map(link => ({ url: link.url, label: link.label })) };
|
|
113
|
+
default:
|
|
114
|
+
return { type: 'progress', message: event.message };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
AuthServerUtil.event = event;
|
|
118
|
+
})(AuthServerUtil || (exports.AuthServerUtil = AuthServerUtil = {}));
|
|
119
|
+
/**
|
|
120
|
+
* pi's `/login` and `/logout` for clients of ta serve. A sign-in runs here, where its credential is
|
|
121
|
+
* kept (auth.json of the agent directory); the client shows what it asks and answers. An OAuth flow that
|
|
122
|
+
* waits for the browser on this machine also asks for the code by hand, for a client elsewhere.
|
|
123
|
+
*/
|
|
124
|
+
let TaAuthServerImpl = class TaAuthServerImpl {
|
|
125
|
+
constructor() {
|
|
126
|
+
this.logins = new Map();
|
|
127
|
+
this.watched = new WeakSet();
|
|
128
|
+
}
|
|
129
|
+
listProviders() {
|
|
130
|
+
return ta_errors_1.TaErrors.guard(async () => {
|
|
131
|
+
const runtime = await this.modelRuntimeProvider.provide();
|
|
132
|
+
const stored = new Set((await runtime.listCredentials()).map(credential => credential.providerId));
|
|
133
|
+
return AuthServerUtil.providers(runtime, stored);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
login(providerId, type) {
|
|
137
|
+
return ta_errors_1.TaErrors.guard(async () => {
|
|
138
|
+
const runtime = await this.modelRuntimeProvider.provide();
|
|
139
|
+
const provider = runtime.getProvider(providerId);
|
|
140
|
+
if (!provider || (type !== 'oauth' && type !== 'api_key') || !provider.auth[type === 'oauth' ? 'oauth' : 'apiKey']) {
|
|
141
|
+
throw ta_errors_1.TaErrors.invalidArgument(`${providerId} has no sign-in of type ${type}.`, 'Pick one of listProviders.');
|
|
142
|
+
}
|
|
143
|
+
const connection = this.connection();
|
|
144
|
+
const login = new Login((0, node_crypto_1.randomBytes)(9).toString('base64url'), connection);
|
|
145
|
+
this.logins.set(login.id, login);
|
|
146
|
+
this.watch(connection);
|
|
147
|
+
// After the answer with its id has gone, so that the client knows whose events come.
|
|
148
|
+
setTimeout(() => void this.run(runtime, login, providerId, type), 0);
|
|
149
|
+
return login.id;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async answer(loginId, promptId, value) {
|
|
153
|
+
var _a, _b;
|
|
154
|
+
const waiting = (_a = this.own(loginId)) === null || _a === void 0 ? void 0 : _a.waiting.get(promptId);
|
|
155
|
+
if (!waiting || typeof value !== 'string') {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
(_b = this.own(loginId)) === null || _b === void 0 ? void 0 : _b.waiting.delete(promptId);
|
|
159
|
+
waiting.resolve(value);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
async cancel(loginId) {
|
|
163
|
+
var _a;
|
|
164
|
+
(_a = this.own(loginId)) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
165
|
+
}
|
|
166
|
+
logout(providerId) {
|
|
167
|
+
return ta_errors_1.TaErrors.guard(async () => (await this.modelRuntimeProvider.provide()).logout(providerId));
|
|
168
|
+
}
|
|
169
|
+
async run(runtime, login, providerId, type) {
|
|
170
|
+
try {
|
|
171
|
+
const settings = await this.settingsManager();
|
|
172
|
+
await runtime.login(providerId, type, { signal: login.abort.signal, prompt: prompt => login.ask(prompt), notify: event => login.send(AuthServerUtil.event(event)) }, { agentName: 'Ta', getDeviceId: () => settings.getOrCreateDeviceId() });
|
|
173
|
+
await this.giveModels(runtime, providerId);
|
|
174
|
+
login.send({ type: 'done' });
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
178
|
+
login.send({ type: 'failed', message, cancelled: message === CANCELLED || login.abort.signal.aborted });
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
this.logins.delete(login.id);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Open sessions that have no model, because none was signed in when they opened, take one of the
|
|
186
|
+
* provider now; sessions that open later choose as pi does.
|
|
187
|
+
*/
|
|
188
|
+
async giveModels(runtime, providerId) {
|
|
189
|
+
const model = (await runtime.getAvailable(providerId))[0];
|
|
190
|
+
if (!model) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
for (const session of this.sessions.list()) {
|
|
194
|
+
const current = session.pi.model;
|
|
195
|
+
if (!current || !runtime.getModel(current.provider, current.id)) {
|
|
196
|
+
await session.pi.setModel(model).catch(() => undefined);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async settingsManager() {
|
|
201
|
+
var _a;
|
|
202
|
+
var _b;
|
|
203
|
+
const sdk = await ai_coding_agent_1.PiSdkUtil.load();
|
|
204
|
+
const agentDir = (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : sdk.getAgentDir();
|
|
205
|
+
return sdk.SettingsManager.create(process.cwd(), agentDir);
|
|
206
|
+
}
|
|
207
|
+
/** Sign-ins belong to the connection that started them. */
|
|
208
|
+
own(loginId) {
|
|
209
|
+
const login = this.logins.get(loginId);
|
|
210
|
+
return login && login.connection === this.connection() ? login : undefined;
|
|
211
|
+
}
|
|
212
|
+
connection() {
|
|
213
|
+
const connection = node_1.RpcContext.connection();
|
|
214
|
+
if (!connection) {
|
|
215
|
+
throw ta_errors_1.TaErrors.invalidArgument('Signing in needs a WebSocket connection.', 'Connect to ta serve over its WebSocket.');
|
|
216
|
+
}
|
|
217
|
+
return connection;
|
|
218
|
+
}
|
|
219
|
+
/** A connection that drops cancels its sign-ins: nobody is left to answer them. */
|
|
220
|
+
watch(connection) {
|
|
221
|
+
if (this.watched.has(connection)) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
this.watched.add(connection);
|
|
225
|
+
connection.onClose(() => {
|
|
226
|
+
for (const login of this.logins.values()) {
|
|
227
|
+
if (login.connection === connection) {
|
|
228
|
+
login.cancel();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
exports.TaAuthServerImpl = TaAuthServerImpl;
|
|
235
|
+
__decorate([
|
|
236
|
+
(0, core_1.Autowired)(ai_coding_agent_1.ModelRuntimeProvider),
|
|
237
|
+
__metadata("design:type", Object)
|
|
238
|
+
], TaAuthServerImpl.prototype, "modelRuntimeProvider", void 0);
|
|
239
|
+
__decorate([
|
|
240
|
+
(0, core_1.Autowired)(host_protocol_1.TaSessionRegistry),
|
|
241
|
+
__metadata("design:type", Object)
|
|
242
|
+
], TaAuthServerImpl.prototype, "sessions", void 0);
|
|
243
|
+
__decorate([
|
|
244
|
+
(0, core_1.Value)(ai_coding_agent_1.CODING_AGENT_OPTIONS),
|
|
245
|
+
__metadata("design:type", Object)
|
|
246
|
+
], TaAuthServerImpl.prototype, "codingAgentOptions", void 0);
|
|
247
|
+
exports.TaAuthServerImpl = TaAuthServerImpl = __decorate([
|
|
248
|
+
(0, rpc_1.Rpc)(ta_protocol_1.TaAuthServer)
|
|
249
|
+
], TaAuthServerImpl);
|
|
250
|
+
//# sourceMappingURL=auth-server-impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-server-impl.js","sourceRoot":"","sources":["../../src/node/auth-server-impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA0C;AAC1C,6DAAyH;AACzH,uCAAgD;AAChD,qCAAkC;AAClC,+CAAsE;AACtE,qDAAwI;AACxI,mDAAoD;AACpD,2CAAuC;AAOvC,qFAAqF;AACrF,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAOpC,wEAAwE;AACxE,MAAM,KAAK;IAKP,YACa,EAAU,EACV,UAAyB;QADzB,OAAE,GAAF,EAAE,CAAQ;QACV,eAAU,GAAV,UAAU,CAAe;QAN7B,UAAK,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9B,YAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;QACpC,eAAU,GA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ACkB;AAG5B;IADlB,IAAA,YAAK,EAAC,sCAAoB,CAAC;;4DAC+B;2BARlD,gBAAgB;IAD5B,IAAA,SAAG,EAAC,0BAAY,CAAC;GACL,gBAAgB,CA8H5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-server-impl.spec.d.ts","sourceRoot":"","sources":["../../src/node/auth-server-impl.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const auth_server_impl_1 = require("./auth-server-impl");
|
|
5
|
+
function runtime() {
|
|
6
|
+
const providers = [
|
|
7
|
+
{ id: 'openai', name: 'OpenAI', auth: { apiKey: { name: 'OpenAI API key', login: async () => ({}) } } },
|
|
8
|
+
{
|
|
9
|
+
id: 'anthropic',
|
|
10
|
+
name: 'Anthropic',
|
|
11
|
+
auth: { oauth: { name: 'Claude Pro/Max', isSubscription: true }, apiKey: { name: 'Anthropic API key', login: async () => ({}) } },
|
|
12
|
+
},
|
|
13
|
+
{ id: 'bedrock', name: 'Amazon Bedrock', auth: { apiKey: { name: 'AWS' } } },
|
|
14
|
+
];
|
|
15
|
+
const configured = {
|
|
16
|
+
anthropic: { configured: true, source: 'stored credential' },
|
|
17
|
+
openai: { configured: true, source: 'OPENAI_API_KEY' },
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
getProviders: () => providers,
|
|
21
|
+
getProviderAuthStatus: (id) => { var _a; return (_a = configured[id]) !== null && _a !== void 0 ? _a : { configured: false }; },
|
|
22
|
+
isUsingOAuth: (id) => id === 'anthropic',
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
(0, bun_test_1.describe)('AuthServerUtil', () => {
|
|
26
|
+
(0, bun_test_1.it)("lists each way to sign in, as pi's /login does, with how each provider is signed in now", () => {
|
|
27
|
+
const list = auth_server_impl_1.AuthServerUtil.providers(runtime(), new Set(['anthropic']));
|
|
28
|
+
(0, bun_test_1.expect)(list.map(provider => `${provider.id}:${provider.type}`)).toEqual(['bedrock:api_key', 'anthropic:oauth', 'anthropic:api_key', 'openai:api_key']);
|
|
29
|
+
const [bedrock, claude, , openai] = list;
|
|
30
|
+
(0, bun_test_1.expect)(bedrock.interactive).toBe(false);
|
|
31
|
+
(0, bun_test_1.expect)(bedrock.configured).toBeUndefined();
|
|
32
|
+
(0, bun_test_1.expect)(claude).toMatchObject({ subscription: true, interactive: true, stored: true, configured: { type: 'oauth', source: 'stored credential' } });
|
|
33
|
+
(0, bun_test_1.expect)(openai).toMatchObject({ stored: false, configured: { type: 'api_key', source: 'OPENAI_API_KEY' } });
|
|
34
|
+
});
|
|
35
|
+
(0, bun_test_1.it)('passes on what a client shows of the events of a sign-in, and nothing else', () => {
|
|
36
|
+
const extra = { openBrowserOnConfirm: true, copyCodeOnConfirm: true };
|
|
37
|
+
(0, bun_test_1.expect)(auth_server_impl_1.AuthServerUtil.event({ type: 'device_code', userCode: 'AB-CD', verificationUri: 'https://x/device', ...extra })).toEqual({
|
|
38
|
+
type: 'device_code',
|
|
39
|
+
userCode: 'AB-CD',
|
|
40
|
+
verificationUri: 'https://x/device',
|
|
41
|
+
expiresInSeconds: undefined,
|
|
42
|
+
});
|
|
43
|
+
(0, bun_test_1.expect)(auth_server_impl_1.AuthServerUtil.event({ type: 'auth_url', url: 'https://x/auth' })).toEqual({ type: 'auth_url', url: 'https://x/auth', instructions: undefined });
|
|
44
|
+
(0, bun_test_1.expect)(auth_server_impl_1.AuthServerUtil.event({ type: 'progress', message: 'Waiting' })).toEqual({ type: 'progress', message: 'Waiting' });
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=auth-server-impl.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-server-impl.spec.js","sourceRoot":"","sources":["../../src/node/auth-server-impl.spec.ts"],"names":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AAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YAC5H,IAAI,EAAE,aAAa;YACnB,QAAQ,EAAE,OAAO;YACjB,eAAe,EAAE,kBAAkB;YACnC,gBAAgB,EAAE,SAAS;SAC9B,CAAC,CAAC;QACH,IAAA,iBAAM,EAAC,iCAAc,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,gBAAgB,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,CAAC;QACxJ,IAAA,iBAAM,EAAC,iCAAc,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAC7H,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { TaClientToolDefinition, TaClientToolRequest, TaClientToolResult, TaEvent } from '@celljs/ta-protocol';
|
|
2
|
+
type ToolDefinition = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).ToolDefinition;
|
|
3
|
+
interface PendingCall {
|
|
4
|
+
request: TaClientToolRequest;
|
|
5
|
+
settle(result: TaClientToolResult | undefined): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The tools a session's clients run. Each is a tool of pi whose `execute` publishes the call and waits
|
|
9
|
+
* for a client's answer: the model, codemode and extensions see it like any other tool. As with
|
|
10
|
+
* dialogs, the call goes to every attached client and the first answer counts. A call ends without a
|
|
11
|
+
* result when the run is aborted or the session closes.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ClientToolBroker {
|
|
14
|
+
protected readonly definitions: TaClientToolDefinition[];
|
|
15
|
+
protected readonly pending: Map<string, PendingCall>;
|
|
16
|
+
protected publish: (event: TaEvent) => void;
|
|
17
|
+
/** Throws CELL_TA_INVALID_ARGUMENT for a definition pi could not take. */
|
|
18
|
+
constructor(definitions?: TaClientToolDefinition[]);
|
|
19
|
+
get pendingRequests(): TaClientToolRequest[];
|
|
20
|
+
/** Where the calls go: the session's event log. */
|
|
21
|
+
connect(publish: (event: TaEvent) => void): void;
|
|
22
|
+
/** The tools for pi. */
|
|
23
|
+
tools(): ToolDefinition[];
|
|
24
|
+
/** False when nobody waits for this call. */
|
|
25
|
+
respond(result: TaClientToolResult): boolean;
|
|
26
|
+
cancelAll(): void;
|
|
27
|
+
protected call(toolName: string, id: string, input: unknown, signal?: AbortSignal): Promise<{
|
|
28
|
+
content: {
|
|
29
|
+
type: 'text';
|
|
30
|
+
text: string;
|
|
31
|
+
}[];
|
|
32
|
+
details: undefined;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=client-tool-broker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-tool-broker.d.ts","sourceRoot":"","sources":["../../src/node/client-tool-broker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGpH,KAAK,cAAc,GAAG,OAAO,iCAAiC,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,cAAc,CAAC;AAEzH,UAAU,WAAW;IACjB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,CAAC;CACxD;AAID;;;;;GAKG;AACH,qBAAa,gBAAgB;IAKb,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,EAAE;IAJpE,SAAS,CAAC,QAAQ,CAAC,OAAO,2BAAkC;IAC5D,SAAS,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAmB;IAE9D,0EAA0E;IAC1E,YAA+B,WAAW,GAAE,sBAAsB,EAAO,EAiBxE;IAED,IAAI,eAAe,IAAI,mBAAmB,EAAE,CAE3C;IAED,mDAAmD;IACnD,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAE/C;IAED,wBAAwB;IACxB,KAAK,IAAI,cAAc,EAAE,CAQxB;IAED,6CAA6C;IAC7C,OAAO,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAI3C;IAED,SAAS,IAAI,IAAI,CAIhB;IAED,SAAS,CAAC,IAAI,CACV,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC;QAAE,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAAC,OAAO,EAAE,SAAS,CAAA;KAAE,CAAC,CAwB5E;CACJ"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientToolBroker = void 0;
|
|
4
|
+
const ta_errors_1 = require("./ta-errors");
|
|
5
|
+
const TOOL_NAME = /^[A-Za-z][\w-]*$/;
|
|
6
|
+
/**
|
|
7
|
+
* The tools a session's clients run. Each is a tool of pi whose `execute` publishes the call and waits
|
|
8
|
+
* for a client's answer: the model, codemode and extensions see it like any other tool. As with
|
|
9
|
+
* dialogs, the call goes to every attached client and the first answer counts. A call ends without a
|
|
10
|
+
* result when the run is aborted or the session closes.
|
|
11
|
+
*/
|
|
12
|
+
class ClientToolBroker {
|
|
13
|
+
/** Throws CELL_TA_INVALID_ARGUMENT for a definition pi could not take. */
|
|
14
|
+
constructor(definitions = []) {
|
|
15
|
+
this.definitions = definitions;
|
|
16
|
+
this.pending = new Map();
|
|
17
|
+
this.publish = () => undefined;
|
|
18
|
+
const names = new Set();
|
|
19
|
+
for (const { name, parameters } of definitions) {
|
|
20
|
+
if (!TOOL_NAME.test(name !== null && name !== void 0 ? name : '') || names.has(name)) {
|
|
21
|
+
throw ta_errors_1.TaErrors.invalidArgument(`The client tool name ${JSON.stringify(name)} is not valid or not unique.`, 'Name each client tool with letters, digits, _ and -, starting with a letter.');
|
|
22
|
+
}
|
|
23
|
+
if ((parameters === null || parameters === void 0 ? void 0 : parameters.type) !== 'object') {
|
|
24
|
+
throw ta_errors_1.TaErrors.invalidArgument(`The parameters of the client tool ${name} are not an object schema.`, 'Pass a JSON schema with type: "object".');
|
|
25
|
+
}
|
|
26
|
+
names.add(name);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
get pendingRequests() {
|
|
30
|
+
return [...this.pending.values()].map(call => call.request);
|
|
31
|
+
}
|
|
32
|
+
/** Where the calls go: the session's event log. */
|
|
33
|
+
connect(publish) {
|
|
34
|
+
this.publish = publish;
|
|
35
|
+
}
|
|
36
|
+
/** The tools for pi. */
|
|
37
|
+
tools() {
|
|
38
|
+
return this.definitions.map(definition => ({
|
|
39
|
+
name: definition.name,
|
|
40
|
+
label: definition.name,
|
|
41
|
+
description: definition.description,
|
|
42
|
+
parameters: definition.parameters,
|
|
43
|
+
execute: (toolCallId, input, signal) => this.call(definition.name, toolCallId, input, signal),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
/** False when nobody waits for this call. */
|
|
47
|
+
respond(result) {
|
|
48
|
+
const call = this.pending.get(result.id);
|
|
49
|
+
call === null || call === void 0 ? void 0 : call.settle(result);
|
|
50
|
+
return call !== undefined;
|
|
51
|
+
}
|
|
52
|
+
cancelAll() {
|
|
53
|
+
for (const call of [...this.pending.values()]) {
|
|
54
|
+
call.settle(undefined);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
call(toolName, id, input, signal) {
|
|
58
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
59
|
+
return Promise.reject(new Error('The run was aborted.'));
|
|
60
|
+
}
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const settle = (result) => {
|
|
63
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
|
|
64
|
+
this.pending.delete(id);
|
|
65
|
+
this.publish({ type: 'client_tool_resolved', id });
|
|
66
|
+
if (!result) {
|
|
67
|
+
reject(new Error(`The client tool ${toolName} got no result: the run was aborted or the session closed.`));
|
|
68
|
+
}
|
|
69
|
+
else if (result.isError) {
|
|
70
|
+
// pi turns a failed tool into an error result for the model.
|
|
71
|
+
reject(new Error(result.output));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
resolve({ content: [{ type: 'text', text: result.output }], details: undefined });
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const onAbort = () => settle(undefined);
|
|
78
|
+
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort, { once: true });
|
|
79
|
+
const request = { type: 'client_tool_request', id, toolName, input };
|
|
80
|
+
this.pending.set(id, { request, settle });
|
|
81
|
+
this.publish(request);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.ClientToolBroker = ClientToolBroker;
|
|
86
|
+
//# sourceMappingURL=client-tool-broker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-tool-broker.js","sourceRoot":"","sources":["../../src/node/client-tool-broker.ts"],"names":[],"mappings":";;;AACA,2CAAuC;AASvC,MAAM,SAAS,GAAG,kBAAkB,CAAC;AAErC;;;;;GAKG;AACH;IAII,0EAA0E;IAC1E,YAA+B,WAAW,GAA6B,EAAE;QAA1C,gBAAW,GAAX,WAA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CAAC,CAAC;gBACnD,IAAI,CAAC,MAAM,EAAE,CAAC;oBACV,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,QAAQ,4DAA4D,CAAC,CAAC,CAAC;gBAC/G,CAAC;qBAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACxB,6DAA6D;oBAC7D,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;gBACrC,CAAC;qBAAM,CAAC;oBACJ,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;gBACtF,CAAC;YACL,CAAC,CAAC;YACF,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACxC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3D,MAAM,OAAO,GAAwB,EAAE,IAAI,EAAE,qBAAqB,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;YAC1F,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC1C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-tool-broker.spec.d.ts","sourceRoot":"","sources":["../../src/node/client-tool-broker.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const client_tool_broker_1 = require("./client-tool-broker");
|
|
5
|
+
const PICK = { name: 'pick_color', description: 'Asks the user for a color.', parameters: { type: 'object', properties: {} } };
|
|
6
|
+
function setup() {
|
|
7
|
+
const events = [];
|
|
8
|
+
const broker = new client_tool_broker_1.ClientToolBroker([PICK]);
|
|
9
|
+
broker.connect(event => events.push(event));
|
|
10
|
+
const [tool] = broker.tools();
|
|
11
|
+
return { broker, events, tool };
|
|
12
|
+
}
|
|
13
|
+
(0, bun_test_1.describe)('ClientToolBroker', () => {
|
|
14
|
+
(0, bun_test_1.it)('is a tool of pi that waits for the first answer of a client', async () => {
|
|
15
|
+
const { broker, events, tool } = setup();
|
|
16
|
+
(0, bun_test_1.expect)(tool.name).toBe('pick_color');
|
|
17
|
+
const result = tool.execute('call-1', { hint: 'warm' });
|
|
18
|
+
(0, bun_test_1.expect)(events).toEqual([{ type: 'client_tool_request', id: 'call-1', toolName: 'pick_color', input: { hint: 'warm' } }]);
|
|
19
|
+
(0, bun_test_1.expect)(broker.pendingRequests).toHaveLength(1);
|
|
20
|
+
(0, bun_test_1.expect)(broker.respond({ id: 'call-1', output: 'red' })).toBe(true);
|
|
21
|
+
(0, bun_test_1.expect)(broker.respond({ id: 'call-1', output: 'blue' })).toBe(false);
|
|
22
|
+
(0, bun_test_1.expect)(await result).toEqual({ content: [{ type: 'text', text: 'red' }], details: undefined });
|
|
23
|
+
(0, bun_test_1.expect)(events.at(-1)).toEqual({ type: 'client_tool_resolved', id: 'call-1' });
|
|
24
|
+
(0, bun_test_1.expect)(broker.pendingRequests).toEqual([]);
|
|
25
|
+
});
|
|
26
|
+
(0, bun_test_1.it)('fails the tool with the output of a failed answer', async () => {
|
|
27
|
+
const { broker, tool } = setup();
|
|
28
|
+
const result = tool.execute('call-2', {});
|
|
29
|
+
broker.respond({ id: 'call-2', output: 'no color today', isError: true });
|
|
30
|
+
await (0, bun_test_1.expect)(result).rejects.toThrow('no color today');
|
|
31
|
+
});
|
|
32
|
+
(0, bun_test_1.it)('ends a call without a result when the run is aborted or the session closes', async () => {
|
|
33
|
+
const { broker, events, tool } = setup();
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
const aborted = tool.execute('call-3', {}, controller.signal);
|
|
36
|
+
controller.abort();
|
|
37
|
+
await (0, bun_test_1.expect)(aborted).rejects.toThrow('got no result');
|
|
38
|
+
const closed = tool.execute('call-4', {});
|
|
39
|
+
broker.cancelAll();
|
|
40
|
+
await (0, bun_test_1.expect)(closed).rejects.toThrow('got no result');
|
|
41
|
+
(0, bun_test_1.expect)(events.filter(event => event.type === 'client_tool_resolved')).toHaveLength(2);
|
|
42
|
+
});
|
|
43
|
+
(0, bun_test_1.it)('refuses definitions pi could not take', () => {
|
|
44
|
+
(0, bun_test_1.expect)(() => new client_tool_broker_1.ClientToolBroker([{ ...PICK, name: 'has space' }])).toThrow('not valid or not unique');
|
|
45
|
+
(0, bun_test_1.expect)(() => new client_tool_broker_1.ClientToolBroker([PICK, PICK])).toThrow('not valid or not unique');
|
|
46
|
+
(0, bun_test_1.expect)(() => new client_tool_broker_1.ClientToolBroker([{ ...PICK, parameters: { type: 'string' } }])).toThrow('not an object schema');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=client-tool-broker.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-tool-broker.spec.js","sourceRoot":"","sources":["../../src/node/client-tool-broker.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAEhD,6DAAwD;AAExD,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,4BAA4B,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC;AAE/H,SAAS,KAAK;IACV,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAG,IAAI,qCAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;I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
import { TaWorkingDirectory } from './working-directory';
|
|
4
|
+
/**
|
|
5
|
+
* Sessions run on this machine, or, with `ta.exec.url`, on the machine of a `ta exec-server`: the
|
|
6
|
+
* agent loop stays here, commands and files are there. All sessions share one connection. The default
|
|
7
|
+
* directory is the one the user chose (TaWorkingDirectory), if any.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DefaultExecEnvironmentFactory implements ExecEnvironmentFactory {
|
|
10
|
+
protected readonly options?: TaExecOptions;
|
|
11
|
+
protected readonly workingDirectory?: TaWorkingDirectory;
|
|
12
|
+
protected client?: ExecClient;
|
|
13
|
+
create(cwd: string): ExecEnvironment;
|
|
14
|
+
/** The working directory the user chose, else that of this process, or of the exec server. */
|
|
15
|
+
defaultCwd(): Promise<string>;
|
|
16
|
+
protected remote(): ExecClient | undefined;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=exec-environment-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec-environment-factory.d.ts","sourceRoot":"","sources":["../../src/node/exec-environment-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,sBAAsB,EAA+C,MAAM,iBAAiB,CAAC;AACxI,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;GAIG;AACH,qBACa,6BAA8B,YAAW,sBAAsB;IAExE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IAI3C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IAEzD,SAAS,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAE9B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAGnC;IAED,8FAA8F;IACxF,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAOlC;IAED,SAAS,CAAC,MAAM,IAAI,UAAU,GAAG,SAAS,CAQzC;CACJ"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultExecEnvironmentFactory = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const ta_exec_1 = require("@celljs/ta-exec");
|
|
15
|
+
const host_protocol_1 = require("./host-protocol");
|
|
16
|
+
const working_directory_1 = require("./working-directory");
|
|
17
|
+
/**
|
|
18
|
+
* Sessions run on this machine, or, with `ta.exec.url`, on the machine of a `ta exec-server`: the
|
|
19
|
+
* agent loop stays here, commands and files are there. All sessions share one connection. The default
|
|
20
|
+
* directory is the one the user chose (TaWorkingDirectory), if any.
|
|
21
|
+
*/
|
|
22
|
+
let DefaultExecEnvironmentFactory = class DefaultExecEnvironmentFactory {
|
|
23
|
+
create(cwd) {
|
|
24
|
+
const client = this.remote();
|
|
25
|
+
return client ? new ta_exec_1.RemoteExecEnvironment(client, cwd) : new ta_exec_1.LocalExecEnvironment(cwd);
|
|
26
|
+
}
|
|
27
|
+
/** The working directory the user chose, else that of this process, or of the exec server. */
|
|
28
|
+
async defaultCwd() {
|
|
29
|
+
var _a;
|
|
30
|
+
const chosen = (_a = this.workingDirectory) === null || _a === void 0 ? void 0 : _a.get();
|
|
31
|
+
if (chosen) {
|
|
32
|
+
return chosen;
|
|
33
|
+
}
|
|
34
|
+
const client = this.remote();
|
|
35
|
+
return client ? (await client.info()).cwd : process.cwd();
|
|
36
|
+
}
|
|
37
|
+
remote() {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const { url, token = '', epoch } = (_a = this.options) !== null && _a !== void 0 ? _a : {};
|
|
40
|
+
if (!url) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
// A host started later fences the ones before it.
|
|
44
|
+
(_b = this.client) !== null && _b !== void 0 ? _b : (this.client = new ta_exec_1.ExecClient({ url, token, epoch: epoch || Date.now() }));
|
|
45
|
+
return this.client;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.DefaultExecEnvironmentFactory = DefaultExecEnvironmentFactory;
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, core_1.Value)(host_protocol_1.TA_EXEC_OPTIONS),
|
|
51
|
+
__metadata("design:type", Object)
|
|
52
|
+
], DefaultExecEnvironmentFactory.prototype, "options", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, core_1.Autowired)(working_directory_1.TaWorkingDirectory),
|
|
55
|
+
(0, core_1.Optional)(),
|
|
56
|
+
__metadata("design:type", Object)
|
|
57
|
+
], DefaultExecEnvironmentFactory.prototype, "workingDirectory", void 0);
|
|
58
|
+
exports.DefaultExecEnvironmentFactory = DefaultExecEnvironmentFactory = __decorate([
|
|
59
|
+
(0, core_1.Component)(ta_exec_1.ExecEnvironmentFactory)
|
|
60
|
+
], DefaultExecEnvironmentFactory);
|
|
61
|
+
//# sourceMappingURL=exec-environment-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec-environment-factory.js","sourceRoot":"","sources":["../../src/node/exec-environment-factory.ts"],"names":[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