@lucid-agents/pi-xgate 0.1.15 → 0.1.17

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 CHANGED
@@ -13,7 +13,7 @@ and the reviewed model-capability snapshot; the internal router contracts packag
13
13
  is not required. With Node 24.19 or later and Pi 1.5.2:
14
14
 
15
15
  ```sh
16
- pi install npm:@lucid-agents/pi-xgate@0.1.15
16
+ pi install npm:@lucid-agents/pi-xgate@0.1.17
17
17
  ```
18
18
 
19
19
  For repository development before a release is available:
@@ -130,6 +130,13 @@ Pi cannot raise the service budget. Authorized ceilings remain consumed after
130
130
  successful settlement even when most of a deposit is returned. A new budget is an
131
131
  explicit wallet-operator action, never automatic rollover or a fresh journal.
132
132
 
133
+ ## Example: model calls and a video through one broker
134
+
135
+ [`examples/video-agent`](examples/video-agent/README.md) runs Pi with this provider on
136
+ Tempo mainnet and adds a tool that buys a Wan 3.0 video through the same wallet broker.
137
+ The broker's `videoDir` setting turns the video routes on; Pi still holds only the broker
138
+ token. It spends real money and needs a funded wallet of your own.
139
+
133
140
  ## Host-injected transport
134
141
 
135
142
  A host that owns payment, such as TaskMarket, builds the provider around its own
@@ -0,0 +1,7 @@
1
+ import { BrokerClient } from "@lucid-agents/xgate-client/broker";
2
+ /** An owner-only regular file at an absolute path, read whole. */
3
+ export declare function privateText(path: string, max?: number): string;
4
+ /** `XGATE_CONFIG`, else `~/.pi/agent/xgate.json`. */
5
+ export declare function defaultConfigPath(): string;
6
+ /** The broker the provider talks to: `{url, tokenFile}` from the private config file. */
7
+ export declare function brokerFromConfig(configPath?: string): BrokerClient;
package/dist/config.js ADDED
@@ -0,0 +1,28 @@
1
+ import { BrokerClient } from "@lucid-agents/xgate-client/broker";
2
+ import { XgateError } from "@lucid-agents/xgate-client/types";
3
+ import { readFileSync, lstatSync } from "node:fs";
4
+ import { isAbsolute, join } from "node:path";
5
+ import { homedir } from "node:os";
6
+ /** An owner-only regular file at an absolute path, read whole. */
7
+ export function privateText(path, max = 8192) {
8
+ if (!isAbsolute(path))
9
+ throw new XgateError("absolute_config_path_required");
10
+ const s = lstatSync(path);
11
+ if (!s.isFile() ||
12
+ s.isSymbolicLink() ||
13
+ (s.mode & 0o077) !== 0 ||
14
+ s.size > max)
15
+ throw new XgateError("private_config_required");
16
+ return readFileSync(path, "utf8").trim();
17
+ }
18
+ /** `XGATE_CONFIG`, else `~/.pi/agent/xgate.json`. */
19
+ export function defaultConfigPath() {
20
+ return (process.env.XGATE_CONFIG ?? join(homedir(), ".pi", "agent", "xgate.json"));
21
+ }
22
+ /** The broker the provider talks to: `{url, tokenFile}` from the private config file. */
23
+ export function brokerFromConfig(configPath = defaultConfigPath()) {
24
+ const cfg = JSON.parse(privateText(configPath));
25
+ if (typeof cfg.url !== "string" || typeof cfg.tokenFile !== "string")
26
+ throw new XgateError("invalid_config");
27
+ return new BrokerClient(cfg.url, privateText(cfg.tokenFile, 128));
28
+ }
package/dist/extension.js CHANGED
@@ -1,26 +1,9 @@
1
1
  import { BrokerClient } from "@lucid-agents/xgate-client/broker";
2
2
  import { XgateError } from "@lucid-agents/xgate-client/types";
3
- import { readFileSync, lstatSync, mkdirSync, writeFileSync } from "node:fs";
4
- import { dirname, isAbsolute, join } from "node:path";
5
- import { homedir } from "node:os";
3
+ import { mkdirSync, writeFileSync } from "node:fs";
4
+ import { dirname } from "node:path";
5
+ import { brokerFromConfig, defaultConfigPath, privateText } from "./config.js";
6
6
  import { createXgateProvider } from "./provider.js";
7
- function privateText(path, max = 8192) {
8
- if (!isAbsolute(path))
9
- throw new XgateError("absolute_config_path_required");
10
- const s = lstatSync(path);
11
- if (!s.isFile() ||
12
- s.isSymbolicLink() ||
13
- (s.mode & 0o077) !== 0 ||
14
- s.size > max)
15
- throw new XgateError("private_config_required");
16
- return readFileSync(path, "utf8").trim();
17
- }
18
- function standalone(configPath) {
19
- const cfg = JSON.parse(privateText(configPath));
20
- if (typeof cfg.url !== "string" || typeof cfg.tokenFile !== "string")
21
- throw new XgateError("invalid_config");
22
- return new BrokerClient(cfg.url, privateText(cfg.tokenFile, 128));
23
- }
24
7
  /** Rail-neutral: atomic units of the named asset; decimals are not assumed. */
25
8
  export function paymentStatus(p) {
26
9
  const left = p.channel
@@ -42,12 +25,12 @@ export function createXgateExtension(options = {}) {
42
25
  export default createXgateExtension();
43
26
  async function register(pi, options) {
44
27
  const injected = options.transport;
45
- const configPath = process.env.XGATE_CONFIG ?? join(homedir(), ".pi", "agent", "xgate.json");
28
+ const configPath = defaultConfigPath();
46
29
  let broker;
47
30
  let context;
48
31
  const load = async () => {
49
32
  const next = injected === undefined
50
- ? standalone(configPath)
33
+ ? brokerFromConfig(configPath)
51
34
  : typeof injected === "function"
52
35
  ? await injected()
53
36
  : injected;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-agents/pi-xgate",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -32,7 +32,7 @@
32
32
  "LICENSE"
33
33
  ],
34
34
  "dependencies": {
35
- "@lucid-agents/xgate-client": "0.1.15"
35
+ "@lucid-agents/xgate-client": "0.1.17"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@earendil-works/pi-ai": "0.85.1 || 1.1.0 || 1.5.2",
@@ -56,10 +56,10 @@
56
56
  "registry": "https://registry.npmjs.org"
57
57
  },
58
58
  "license": "MIT",
59
- "gitHead": "4d998df40940dcd49b0147fa77b3b1313cd0f20a",
59
+ "gitHead": "b50acd791679fab952109febbc2c49aecc20626c",
60
60
  "xgateRelease": {
61
- "version": "v0.1.15",
62
- "sourceSha": "4d998df40940dcd49b0147fa77b3b1313cd0f20a",
63
- "candidateId": "rc-4d998df40940-43388493545-1"
61
+ "version": "v0.1.17",
62
+ "sourceSha": "b50acd791679fab952109febbc2c49aecc20626c",
63
+ "candidateId": "rc-b50acd791679-43759708185-1"
64
64
  }
65
65
  }
package/src/config.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { BrokerClient } from "@lucid-agents/xgate-client/broker";
2
+ import { XgateError } from "@lucid-agents/xgate-client/types";
3
+ import { readFileSync, lstatSync } from "node:fs";
4
+ import { isAbsolute, join } from "node:path";
5
+ import { homedir } from "node:os";
6
+
7
+ /** An owner-only regular file at an absolute path, read whole. */
8
+ export function privateText(path: string, max = 8192): string {
9
+ if (!isAbsolute(path)) throw new XgateError("absolute_config_path_required");
10
+ const s = lstatSync(path);
11
+ if (
12
+ !s.isFile() ||
13
+ s.isSymbolicLink() ||
14
+ (s.mode & 0o077) !== 0 ||
15
+ s.size > max
16
+ )
17
+ throw new XgateError("private_config_required");
18
+ return readFileSync(path, "utf8").trim();
19
+ }
20
+ /** `XGATE_CONFIG`, else `~/.pi/agent/xgate.json`. */
21
+ export function defaultConfigPath(): string {
22
+ return (
23
+ process.env.XGATE_CONFIG ?? join(homedir(), ".pi", "agent", "xgate.json")
24
+ );
25
+ }
26
+ /** The broker the provider talks to: `{url, tokenFile}` from the private config file. */
27
+ export function brokerFromConfig(
28
+ configPath: string = defaultConfigPath(),
29
+ ): BrokerClient {
30
+ const cfg = JSON.parse(privateText(configPath));
31
+ if (typeof cfg.url !== "string" || typeof cfg.tokenFile !== "string")
32
+ throw new XgateError("invalid_config");
33
+ return new BrokerClient(cfg.url, privateText(cfg.tokenFile, 128));
34
+ }
package/src/extension.ts CHANGED
@@ -4,9 +4,9 @@ import type {
4
4
  } from "@earendil-works/pi-coding-agent";
5
5
  import { BrokerClient } from "@lucid-agents/xgate-client/broker";
6
6
  import { XgateError } from "@lucid-agents/xgate-client/types";
7
- import { readFileSync, lstatSync, mkdirSync, writeFileSync } from "node:fs";
8
- import { dirname, isAbsolute, join } from "node:path";
9
- import { homedir } from "node:os";
7
+ import { mkdirSync, writeFileSync } from "node:fs";
8
+ import { dirname } from "node:path";
9
+ import { brokerFromConfig, defaultConfigPath, privateText } from "./config.ts";
10
10
  import { createXgateProvider, type XgatePurchaseFailure } from "./provider.ts";
11
11
  import type { XgatePayment, XgateTransport } from "./transport.ts";
12
12
  export interface XgateExtensionOptions {
@@ -17,24 +17,6 @@ export interface XgateExtensionOptions {
17
17
  */
18
18
  transport?: XgateTransport | (() => XgateTransport | Promise<XgateTransport>);
19
19
  }
20
- function privateText(path: string, max = 8192): string {
21
- if (!isAbsolute(path)) throw new XgateError("absolute_config_path_required");
22
- const s = lstatSync(path);
23
- if (
24
- !s.isFile() ||
25
- s.isSymbolicLink() ||
26
- (s.mode & 0o077) !== 0 ||
27
- s.size > max
28
- )
29
- throw new XgateError("private_config_required");
30
- return readFileSync(path, "utf8").trim();
31
- }
32
- function standalone(configPath: string): BrokerClient {
33
- const cfg = JSON.parse(privateText(configPath));
34
- if (typeof cfg.url !== "string" || typeof cfg.tokenFile !== "string")
35
- throw new XgateError("invalid_config");
36
- return new BrokerClient(cfg.url, privateText(cfg.tokenFile, 128));
37
- }
38
20
  /** Rail-neutral: atomic units of the named asset; decimals are not assumed. */
39
21
  export function paymentStatus(p: XgatePayment): string {
40
22
  const left = p.channel
@@ -61,14 +43,13 @@ async function register(
61
43
  options: XgateExtensionOptions,
62
44
  ): Promise<void> {
63
45
  const injected = options.transport;
64
- const configPath =
65
- process.env.XGATE_CONFIG ?? join(homedir(), ".pi", "agent", "xgate.json");
46
+ const configPath = defaultConfigPath();
66
47
  let broker: XgateTransport | undefined;
67
48
  let context: ExtensionContext | undefined;
68
49
  const load = async () => {
69
50
  const next =
70
51
  injected === undefined
71
- ? standalone(configPath)
52
+ ? brokerFromConfig(configPath)
72
53
  : typeof injected === "function"
73
54
  ? await injected()
74
55
  : injected;