@agentuity/server 0.0.48 → 0.0.50

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 (44) hide show
  1. package/dist/api/api.d.ts.map +1 -1
  2. package/dist/api/api.js +5 -0
  3. package/dist/api/api.js.map +1 -1
  4. package/dist/api/index.d.ts +1 -0
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/api/index.js +1 -0
  7. package/dist/api/index.js.map +1 -1
  8. package/dist/api/project/deploy.d.ts +10 -0
  9. package/dist/api/project/deploy.d.ts.map +1 -1
  10. package/dist/api/project/deploy.js +6 -1
  11. package/dist/api/project/deploy.js.map +1 -1
  12. package/dist/api/project/deployment.d.ts.map +1 -1
  13. package/dist/api/project/deployment.js +18 -10
  14. package/dist/api/project/deployment.js.map +1 -1
  15. package/dist/api/session/get.d.ts +33 -0
  16. package/dist/api/session/get.d.ts.map +1 -0
  17. package/dist/api/session/get.js +33 -0
  18. package/dist/api/session/get.js.map +1 -0
  19. package/dist/api/session/index.d.ts +7 -0
  20. package/dist/api/session/index.d.ts.map +1 -0
  21. package/dist/api/session/index.js +4 -0
  22. package/dist/api/session/index.js.map +1 -0
  23. package/dist/api/session/list.d.ts +127 -0
  24. package/dist/api/session/list.d.ts.map +1 -0
  25. package/dist/api/session/list.js +73 -0
  26. package/dist/api/session/list.js.map +1 -0
  27. package/dist/api/session/logs.d.ts +23 -0
  28. package/dist/api/session/logs.d.ts.map +1 -0
  29. package/dist/api/session/logs.js +27 -0
  30. package/dist/api/session/logs.js.map +1 -0
  31. package/dist/server.d.ts +13 -3
  32. package/dist/server.d.ts.map +1 -1
  33. package/dist/server.js +46 -6
  34. package/dist/server.js.map +1 -1
  35. package/package.json +4 -2
  36. package/src/api/api.ts +7 -0
  37. package/src/api/index.ts +1 -0
  38. package/src/api/project/deploy.ts +6 -1
  39. package/src/api/project/deployment.ts +55 -26
  40. package/src/api/session/get.ts +62 -0
  41. package/src/api/session/index.ts +6 -0
  42. package/src/api/session/list.ts +107 -0
  43. package/src/api/session/logs.ts +46 -0
  44. package/src/server.ts +57 -7
package/src/server.ts CHANGED
@@ -3,6 +3,7 @@ import type {
3
3
  FetchErrorResponse,
4
4
  FetchResponse,
5
5
  FetchAdapter,
6
+ Logger,
6
7
  } from '@agentuity/core';
7
8
  import { ServiceException, toServiceException, fromResponse } from '@agentuity/core';
8
9
 
@@ -17,14 +18,61 @@ interface ServiceAdapterConfig {
17
18
  ) => Promise<void>;
18
19
  }
19
20
 
21
+ const sensitiveHeaders = new Set(['authorization', 'x-api-key']);
22
+
23
+ /**
24
+ * Redacts the middle of a string while keeping a prefix and suffix visible.
25
+ * Ensures that if the string is too short, everything is redacted.
26
+ *
27
+ * @param input The string to redact
28
+ * @param prefix Number of chars to keep at the start
29
+ * @param suffix Number of chars to keep at the end
30
+ * @param mask Character used for redaction
31
+ */
32
+ export function redact(
33
+ input: string,
34
+ prefix: number = 4,
35
+ suffix: number = 4,
36
+ mask: string = '*'
37
+ ): string {
38
+ if (!input) return '';
39
+
40
+ // If revealing prefix+suffix would leak too much, fully mask
41
+ if (input.length <= prefix + suffix) {
42
+ return mask.repeat(input.length);
43
+ }
44
+
45
+ const start = input.slice(0, prefix);
46
+ const end = input.slice(-suffix);
47
+ const hiddenLength = input.length - prefix - suffix;
48
+
49
+ return start + mask.repeat(hiddenLength) + end;
50
+ }
51
+
52
+ const redactHeaders = (kv: Record<string, string>): string => {
53
+ const values: string[] = [];
54
+ for (const k of Object.keys(kv)) {
55
+ const _k = k.toLowerCase();
56
+ const v = kv[k];
57
+ if (sensitiveHeaders.has(_k)) {
58
+ values.push(`${_k}=${redact(v)}`);
59
+ } else {
60
+ values.push(`${_k}=${v}`);
61
+ }
62
+ }
63
+ return '[' + values.join(',') + ']';
64
+ };
65
+
20
66
  class ServerFetchAdapter implements FetchAdapter {
21
67
  #config: ServiceAdapterConfig;
68
+ #logger: Logger;
22
69
 
23
- constructor(config: ServiceAdapterConfig) {
70
+ constructor(config: ServiceAdapterConfig, logger: Logger) {
24
71
  this.#config = config;
72
+ this.#logger = logger;
25
73
  }
26
74
  private async _invoke<T>(url: string, options: FetchRequest): Promise<FetchResponse<T>> {
27
- const headers = {
75
+ const headers: Record<string, string> = {
28
76
  ...options.headers,
29
77
  ...this.#config.headers,
30
78
  };
@@ -37,8 +85,10 @@ class ServerFetchAdapter implements FetchAdapter {
37
85
  ) {
38
86
  headers['Content-Type'] = 'application/octet-stream';
39
87
  }
88
+ const method = options.method ?? 'POST';
89
+ this.#logger.trace('sending %s to %s with headers: %s', method, url, redactHeaders(headers));
40
90
  const res = await fetch(url, {
41
- method: options.method ?? 'POST',
91
+ method,
42
92
  body: options.body,
43
93
  headers,
44
94
  signal: options.signal,
@@ -66,7 +116,7 @@ class ServerFetchAdapter implements FetchAdapter {
66
116
  response: res,
67
117
  };
68
118
  }
69
- const data = await fromResponse<T>(url, res);
119
+ const data = await fromResponse<T>(method, url, res);
70
120
  return {
71
121
  ok: true,
72
122
  data,
@@ -79,7 +129,7 @@ class ServerFetchAdapter implements FetchAdapter {
79
129
  response: res,
80
130
  } as FetchErrorResponse;
81
131
  }
82
- const err = await toServiceException(url, res);
132
+ const err = await toServiceException(method, url, res);
83
133
  throw err;
84
134
  }
85
135
  async invoke<T>(
@@ -128,6 +178,6 @@ class ServerFetchAdapter implements FetchAdapter {
128
178
  * @param config the service config
129
179
  * @returns
130
180
  */
131
- export function createServerFetchAdapter(config: ServiceAdapterConfig) {
132
- return new ServerFetchAdapter(config);
181
+ export function createServerFetchAdapter(config: ServiceAdapterConfig, logger: Logger) {
182
+ return new ServerFetchAdapter(config, logger);
133
183
  }