@awarevue/agent-sdk 2.0.21 → 2.0.22

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/dist/agent-app.js CHANGED
@@ -4,6 +4,7 @@ exports.AgentApp = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const default_validator_1 = require("./default-validator");
6
6
  const utils_1 = require("./utils");
7
+ const agent_error_1 = require("./agent-error");
7
8
  class AgentApp {
8
9
  constructor(agent, options) {
9
10
  this.agent = agent;
@@ -32,6 +33,7 @@ class AgentApp {
32
33
  kind: 'error-rs',
33
34
  requestId,
34
35
  error: (0, utils_1.stringifyError)(error),
36
+ code: error instanceof agent_error_1.AgentError ? error.code : undefined,
35
37
  })), (0, rxjs_1.tap)((rs) => this.options.transport.send(this.addEnvelope(rs))));
36
38
  this.addEnvelope = (payload) => ({
37
39
  ...payload,
@@ -86,13 +88,20 @@ class AgentApp {
86
88
  // handle commands
87
89
  case 'command':
88
90
  return this.agent.runCommand$(context, message).pipe(
91
+ // if command observable completes without emitting, throw not supported error
92
+ (0, rxjs_1.throwIfEmpty)(() => new agent_error_1.AgentError(`Agent ${context.provider} does not support command ${message.command}`, 'NOT_SUPPORTED')),
89
93
  // success
90
94
  (0, rxjs_1.map)(() => ({
91
95
  kind: 'command-rs',
92
96
  requestId: message.id,
93
97
  })), this.handleResponse$(message.id));
94
98
  case 'query':
99
+ if (!this.agent.getResult$) {
100
+ return (0, rxjs_1.throwError)(() => new agent_error_1.AgentError(`Agent ${context.provider} does not support queries`, 'NOT_SUPPORTED'));
101
+ }
95
102
  return this.agent.getResult$(context, message).pipe(
103
+ // if query observable completes without emitting, throw not supported error
104
+ (0, rxjs_1.throwIfEmpty)(() => new agent_error_1.AgentError(`Agent ${context.provider} does not support query ${message.query}`, 'NOT_SUPPORTED')),
96
105
  // success
97
106
  (0, rxjs_1.map)((result) => ({
98
107
  kind: 'query-rs',
@@ -101,7 +110,7 @@ class AgentApp {
101
110
  })), this.handleResponse$(message.id));
102
111
  case 'push-file':
103
112
  if (!this.agent.pushFile) {
104
- return (0, rxjs_1.throwError)(() => new Error(`Agent ${context.provider} does not support file pushing`));
113
+ return (0, rxjs_1.throwError)(() => new agent_error_1.AgentError(`Agent ${context.provider} does not support file pushing`, 'NOT_SUPPORTED'));
105
114
  }
106
115
  return this.agent.pushFile(context, message).pipe(
107
116
  // success - no return value
@@ -116,16 +125,18 @@ class AgentApp {
116
125
  requestId: message.id,
117
126
  })), this.handleResponse$(message.id));
118
127
  case 'validate-change':
119
- // validate access change
120
- const validateOb$ = !this.agent.validateAccessChange$
121
- ? (0, rxjs_1.throwError)(() => new Error(`Agent ${context.provider} does not support access change validation`))
122
- : changeValidator$(context, message).pipe((0, rxjs_1.mergeMap)(([issues, cache]) => {
128
+ const validateOb$ = (0, rxjs_1.throwError)(() => new agent_error_1.AgentError(`Agent ${context.provider} does not support access change validation`, 'NOT_SUPPORTED'));
129
+ if (this.agent.validateAccessChange$) {
130
+ const v$ = this.agent.validateAccessChange$;
131
+ // validate access change
132
+ return changeValidator$(context, message).pipe((0, rxjs_1.mergeMap)(([issues, cache]) => {
123
133
  objectCache = cache;
124
134
  const validationContext = this.createAccessChangeContext(context, message.refMap, objectCache);
125
135
  return issues.length > 0
126
136
  ? (0, rxjs_1.of)(issues)
127
- : this.agent.validateAccessChange$(validationContext, message);
137
+ : v$(validationContext, message);
128
138
  }));
139
+ }
129
140
  return validateOb$.pipe((0, rxjs_1.map)((issues) => ({
130
141
  kind: 'validate-change-rs',
131
142
  requestId: message.id,
@@ -135,7 +146,7 @@ class AgentApp {
135
146
  // apply access change
136
147
  const applyContext = this.createAccessChangeContext(context, message.refMap, objectCache);
137
148
  const applyOb$ = !this.agent.applyAccessChange$
138
- ? (0, rxjs_1.throwError)(() => new Error(`Agent ${context.provider} does not support access change apply`))
149
+ ? (0, rxjs_1.throwError)(() => new agent_error_1.AgentError(`Agent ${context.provider} does not support access change apply`, 'NOT_SUPPORTED'))
139
150
  : this.agent.applyAccessChange$(applyContext, message);
140
151
  return applyOb$.pipe((0, rxjs_1.map)((result) => ({
141
152
  kind: 'apply-change-rs',
@@ -0,0 +1,5 @@
1
+ import { AgentErrorCode } from '@awarevue/api-types';
2
+ export declare class AgentError extends Error {
3
+ readonly code: AgentErrorCode;
4
+ constructor(message: string, code: AgentErrorCode);
5
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentError = void 0;
4
+ class AgentError extends Error {
5
+ constructor(message, code) {
6
+ super(message);
7
+ this.code = code;
8
+ this.name = 'AgentError';
9
+ }
10
+ }
11
+ exports.AgentError = AgentError;
@@ -2,7 +2,7 @@ import { AccessValidateChangeRq } from '@awarevue/api-types';
2
2
  import { Agent, Context } from './agent';
3
3
  export declare const createValidator: <T extends Agent>(agent: T) => (context: Context, change: AccessValidateChangeRq) => import("rxjs").Observable<readonly [{
4
4
  index?: number | undefined;
5
- code?: "BAD_REFERENCE" | "NOT_FOUND" | "NOT_UNIQUE" | "INVALID" | "NOT_SUPPORTED" | undefined;
5
+ code?: "NOT_SUPPORTED" | "BAD_REFERENCE" | "NOT_FOUND" | "NOT_UNIQUE" | "INVALID" | undefined;
6
6
  message?: string | undefined;
7
7
  path?: string | undefined;
8
8
  objectId?: string | undefined;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awarevue/agent-sdk",
3
- "version": "2.0.21",
3
+ "version": "2.0.22",
4
4
  "description": "SDK for building Agent implementations that speak the Aware protocol.",
5
5
  "author": "Yaser Awajan",
6
6
  "license": "MIT",
@@ -27,13 +27,14 @@
27
27
  "lint:fix": "yarn lint --fix"
28
28
  },
29
29
  "dependencies": {
30
- "@awarevue/api-types": "^2.0.21",
30
+ "@awarevue/api-types": "^2.0.22",
31
31
  "rxjs": "^7.8.2",
32
32
  "ws": "^8",
33
33
  "zod": "3.24.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^20.12.7",
37
+ "@types/ws": "^8.18.1",
37
38
  "@typescript-eslint/eslint-plugin": "^8.31.1",
38
39
  "@typescript-eslint/parser": "^8.31.1",
39
40
  "eslint": "^9.25.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awarevue/agent-sdk",
3
- "version": "2.0.21",
3
+ "version": "2.0.22",
4
4
  "description": "SDK for building Agent implementations that speak the Aware protocol.",
5
5
  "author": "Yaser Awajan",
6
6
  "license": "MIT",
@@ -27,13 +27,14 @@
27
27
  "lint:fix": "yarn lint --fix"
28
28
  },
29
29
  "dependencies": {
30
- "@awarevue/api-types": "^2.0.21",
30
+ "@awarevue/api-types": "^2.0.22",
31
31
  "rxjs": "^7.8.2",
32
32
  "ws": "^8",
33
33
  "zod": "3.24.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^20.12.7",
37
+ "@types/ws": "^8.18.1",
37
38
  "@typescript-eslint/eslint-plugin": "^8.31.1",
38
39
  "@typescript-eslint/parser": "^8.31.1",
39
40
  "eslint": "^9.25.1",