@celljs/ta-gateway 4.15.2 → 4.16.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.
Files changed (51) hide show
  1. package/esm/node/command-sandbox.d.ts +1 -0
  2. package/esm/node/command-sandbox.js +10 -1
  3. package/esm/node/docker-engine.d.ts +5 -0
  4. package/esm/node/docker-engine.js +11 -0
  5. package/esm/node/docker-sandbox.d.ts +3 -0
  6. package/esm/node/docker-sandbox.js +17 -3
  7. package/esm/node/environments.d.ts +2 -0
  8. package/esm/node/environments.js +5 -3
  9. package/esm/node/gateway-exec.d.ts +19 -0
  10. package/esm/node/gateway-exec.js +65 -0
  11. package/esm/node/gateway-policy.d.ts +1 -0
  12. package/esm/node/gateway-policy.js +2 -1
  13. package/esm/node/gateway-quotas.d.ts +9 -1
  14. package/esm/node/gateway-quotas.js +34 -3
  15. package/esm/node/gateway-server.d.ts +12 -1
  16. package/esm/node/gateway-server.js +55 -4
  17. package/esm/node/gateway-service.d.ts +8 -0
  18. package/esm/node/gateway-service.js +23 -4
  19. package/esm/node/local-sandbox.d.ts +1 -0
  20. package/esm/node/local-sandbox.js +2 -1
  21. package/esm/node/model-proxy.d.ts +105 -0
  22. package/esm/node/model-proxy.js +435 -0
  23. package/esm/node/sandbox-provider.d.ts +7 -0
  24. package/esm/node/tenant-store.d.ts +7 -0
  25. package/esm/node/tenant-store.js +10 -0
  26. package/lib/node/command-sandbox.d.ts +1 -0
  27. package/lib/node/command-sandbox.js +10 -1
  28. package/lib/node/docker-engine.d.ts +5 -0
  29. package/lib/node/docker-engine.js +11 -0
  30. package/lib/node/docker-sandbox.d.ts +3 -0
  31. package/lib/node/docker-sandbox.js +17 -3
  32. package/lib/node/environments.d.ts +2 -0
  33. package/lib/node/environments.js +5 -3
  34. package/lib/node/gateway-exec.d.ts +20 -0
  35. package/lib/node/gateway-exec.js +69 -0
  36. package/lib/node/gateway-policy.d.ts +1 -0
  37. package/lib/node/gateway-policy.js +2 -1
  38. package/lib/node/gateway-quotas.d.ts +9 -1
  39. package/lib/node/gateway-quotas.js +34 -3
  40. package/lib/node/gateway-server.d.ts +12 -1
  41. package/lib/node/gateway-server.js +55 -4
  42. package/lib/node/gateway-service.d.ts +8 -0
  43. package/lib/node/gateway-service.js +23 -4
  44. package/lib/node/local-sandbox.d.ts +1 -0
  45. package/lib/node/local-sandbox.js +2 -1
  46. package/lib/node/model-proxy.d.ts +106 -0
  47. package/lib/node/model-proxy.js +440 -0
  48. package/lib/node/sandbox-provider.d.ts +7 -0
  49. package/lib/node/tenant-store.d.ts +7 -0
  50. package/lib/node/tenant-store.js +10 -0
  51. package/package.json +4 -4
@@ -5,6 +5,9 @@ export interface TenantMeter {
5
5
  month: string;
6
6
  runMs: number;
7
7
  bonusMinutes: number;
8
+ /** Tokens and dollars of calls of models through the gateway. */
9
+ tokens?: number;
10
+ cost?: number;
8
11
  }
9
12
  /** A tenant: an account and its Ta, wherever it runs. */
10
13
  export interface Tenant {
@@ -22,6 +25,8 @@ export interface Tenant {
22
25
  limits?: TaGatewayLimits;
23
26
  suspended?: boolean;
24
27
  meter?: TenantMeter;
28
+ /** What its sandbox calls the models of the gateway with: it reaches no key of a provider. */
29
+ modelKey?: string;
25
30
  }
26
31
  /** Files written whole or not at all, readable by this user only. */
27
32
  export declare function writePrivate(file: string, data: unknown): void;
@@ -42,6 +47,8 @@ export declare class TenantStore {
42
47
  avatar?: string;
43
48
  }, now?: number): Tenant;
44
49
  update(id: string, change: Partial<Omit<Tenant, 'id' | 'account' | 'token'>>): Tenant;
50
+ /** Its model key, made for a tenant of before. */
51
+ modelKey(id: string): string;
45
52
  list(): Tenant[];
46
53
  protected save(tenant: Tenant): void;
47
54
  }
@@ -59,6 +59,7 @@ class TenantStore {
59
59
  name: account.name,
60
60
  avatar: account.avatar,
61
61
  token: (0, node_crypto_1.randomBytes)(32).toString('base64url'),
62
+ modelKey: `tam-${(0, node_crypto_1.randomBytes)(24).toString('base64url')}`,
62
63
  createdAt: now,
63
64
  };
64
65
  this.save(tenant);
@@ -73,6 +74,15 @@ class TenantStore {
73
74
  this.save(next);
74
75
  return next;
75
76
  }
77
+ /** Its model key, made for a tenant of before. */
78
+ modelKey(id) {
79
+ var _a;
80
+ const tenant = this.get(id);
81
+ if (!tenant) {
82
+ throw new Error(`No tenant ${id}`);
83
+ }
84
+ return (_a = tenant.modelKey) !== null && _a !== void 0 ? _a : this.update(id, { modelKey: `tam-${(0, node_crypto_1.randomBytes)(24).toString('base64url')}` }).modelKey;
85
+ }
76
86
  list() {
77
87
  return (0, node_fs_1.readdirSync)(this.dir)
78
88
  .filter(name => /^[0-9a-f]{16}\.json$/.test(name))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-gateway",
3
- "version": "4.15.2",
3
+ "version": "4.16.0",
4
4
  "description": "ta gateway: one Ta per account, each in a sandbox of its own, behind one sign-in",
5
5
  "homepage": "https://github.com/cellbang/ta",
6
6
  "bugs": {
@@ -29,9 +29,9 @@
29
29
  "watch": "tsc -b -w --preserveWatchOutput"
30
30
  },
31
31
  "dependencies": {
32
- "@celljs/rpc": "4.15.2",
33
- "@celljs/ta-host": "4.15.2",
34
- "@celljs/ta-protocol": "4.15.2"
32
+ "@celljs/rpc": "4.16.0",
33
+ "@celljs/ta-host": "4.16.0",
34
+ "@celljs/ta-protocol": "4.16.0"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"