@sprucelabs/spruce-agent-utils 0.0.2 → 0.1.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.
@@ -3,13 +3,13 @@
3
3
  "skipped": []
4
4
  },
5
5
  "skipped": [
6
- "skill"
6
+ "event",
7
+ "skill",
8
+ "permission"
7
9
  ],
8
10
  "installed": [
9
11
  "test",
10
12
  "schema",
11
- "error",
12
- "permission",
13
- "event"
13
+ "error"
14
14
  ]
15
15
  }
@@ -1,9 +1,9 @@
1
1
  import { MercuryClient } from '@sprucelabs/mercury-client';
2
2
  export default class SpruceAgent implements AgentLoader {
3
3
  private static instance?;
4
- private client;
4
+ private connectToApi;
5
5
  private constructor();
6
- static setup(client: MercuryClient): void;
6
+ static setup(client: MercuryClient | ConnectFactory): void;
7
7
  static reset(): void;
8
8
  static getInstance(): SpruceAgent;
9
9
  getName(): Promise<string>;
@@ -11,3 +11,5 @@ export default class SpruceAgent implements AgentLoader {
11
11
  export interface AgentLoader {
12
12
  getName(): Promise<string>;
13
13
  }
14
+ type ConnectFactory = () => Promise<MercuryClient>;
15
+ export {};
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("./errors/SpruceError"));
7
7
  class SpruceAgent {
8
8
  constructor(client) {
9
- this.client = client;
9
+ this.connectToApi =
10
+ typeof client === 'function' ? client : async () => client;
10
11
  }
11
12
  static setup(client) {
12
13
  this.instance = new SpruceAgent(client);
@@ -23,7 +24,8 @@ class SpruceAgent {
23
24
  });
24
25
  }
25
26
  async getName() {
26
- const [{ name }] = await this.client.emitAndFlattenResponses('get-agent-name::v2020_12_25');
27
+ const client = await this.connectToApi();
28
+ const [{ name }] = await client.emitAndFlattenResponses('get-agent-name::v2020_12_25');
27
29
  return name;
28
30
  }
29
31
  }
@@ -24,7 +24,7 @@ const agentAssert = {
24
24
  },
25
25
  includesAgentName: (text) => {
26
26
  (0, schema_1.assertOptions)({ text }, ['text']);
27
- test_utils_1.assert.doesInclude(text, name, `The tex must include agent name!`);
27
+ test_utils_1.assert.doesInclude(text, name, `The text must include agent name!`);
28
28
  },
29
29
  };
30
30
  exports.default = agentAssert;
@@ -11,7 +11,7 @@ class SpruceError extends error_1.default {
11
11
  let message;
12
12
  switch (options?.code) {
13
13
  case 'AGENT_LOADER_NOT_CONFIGURED':
14
- message = `The agent loader has not been configured. Please call AgentLoader.setup(...) first. Best place is probably in the did-boot of your skill.`;
14
+ message = `The agent loader has not been configured. Please call SpruceAgent.setup(...) first. Best place is probably in the did-boot of your skill or the constructor of your AppViewController in the front-end.`;
15
15
  break;
16
16
  default:
17
17
  message = super.friendlyMessage();
@@ -1,9 +1,9 @@
1
1
  import { MercuryClient } from '@sprucelabs/mercury-client';
2
2
  export default class SpruceAgent implements AgentLoader {
3
3
  private static instance?;
4
- private client;
4
+ private connectToApi;
5
5
  private constructor();
6
- static setup(client: MercuryClient): void;
6
+ static setup(client: MercuryClient | ConnectFactory): void;
7
7
  static reset(): void;
8
8
  static getInstance(): SpruceAgent;
9
9
  getName(): Promise<string>;
@@ -11,3 +11,5 @@ export default class SpruceAgent implements AgentLoader {
11
11
  export interface AgentLoader {
12
12
  getName(): Promise<string>;
13
13
  }
14
+ type ConnectFactory = () => Promise<MercuryClient>;
15
+ export {};
@@ -1,7 +1,8 @@
1
1
  import SpruceError from './errors/SpruceError.js';
2
2
  export default class SpruceAgent {
3
3
  constructor(client) {
4
- this.client = client;
4
+ this.connectToApi =
5
+ typeof client === 'function' ? client : async () => client;
5
6
  }
6
7
  static setup(client) {
7
8
  this.instance = new SpruceAgent(client);
@@ -18,7 +19,8 @@ export default class SpruceAgent {
18
19
  });
19
20
  }
20
21
  async getName() {
21
- const [{ name }] = await this.client.emitAndFlattenResponses('get-agent-name::v2020_12_25');
22
+ const client = await this.connectToApi();
23
+ const [{ name }] = await client.emitAndFlattenResponses('get-agent-name::v2020_12_25');
22
24
  return name;
23
25
  }
24
26
  }
@@ -19,7 +19,7 @@ const agentAssert = {
19
19
  },
20
20
  includesAgentName: (text) => {
21
21
  assertOptions({ text }, ['text']);
22
- assert.doesInclude(text, name, `The tex must include agent name!`);
22
+ assert.doesInclude(text, name, `The text must include agent name!`);
23
23
  },
24
24
  };
25
25
  export default agentAssert;
@@ -6,7 +6,7 @@ export default class SpruceError extends BaseSpruceError {
6
6
  let message;
7
7
  switch (options === null || options === void 0 ? void 0 : options.code) {
8
8
  case 'AGENT_LOADER_NOT_CONFIGURED':
9
- message = `The agent loader has not been configured. Please call AgentLoader.setup(...) first. Best place is probably in the did-boot of your skill.`;
9
+ message = `The agent loader has not been configured. Please call SpruceAgent.setup(...) first. Best place is probably in the did-boot of your skill or the constructor of your AppViewController in the front-end.`;
10
10
  break;
11
11
  default:
12
12
  message = super.friendlyMessage();
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "0.0.2",
11
+ "version": "0.1.0",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",
@@ -40,10 +40,10 @@
40
40
  "watch.tsc": "tsc -w"
41
41
  },
42
42
  "devDependencies": {
43
- "@sprucelabs/esm-postbuild": "^8.0.0",
43
+ "@sprucelabs/esm-postbuild": "^9.0.8",
44
44
  "@sprucelabs/jest-json-reporter": "^10.0.12",
45
- "@sprucelabs/semantic-release": "^6.0.0",
46
45
  "@sprucelabs/resolve-path-aliases": "^4.0.9",
46
+ "@sprucelabs/semantic-release": "^6.0.0",
47
47
  "@sprucelabs/spruce-test-fixtures": "^76.0.15",
48
48
  "@sprucelabs/test": "^11.0.3",
49
49
  "@sprucelabs/test-utils": "^7.0.16",
@@ -53,7 +53,7 @@
53
53
  "eslint-config-spruce": "^11.2.26",
54
54
  "jest": "^30.2.0",
55
55
  "jest-circus": "^30.2.0",
56
- "prettier": "^3.7.3",
56
+ "prettier": "^3.7.4",
57
57
  "ts-node": "^10.9.2",
58
58
  "tsc-watch": "^7.2.0",
59
59
  "typescript": "^5.9.3"
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.types.js","sourceRoot":"","sources":["../../../src/.spruce/errors/errors.types.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.types.js","sourceRoot":"","sources":["../../../src/.spruce/errors/options.types.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"agentLoaderNotConfigured.schema.js","sourceRoot":"","sources":["../../../../src/.spruce/errors/spruceAgentUtils/agentLoaderNotConfigured.schema.ts"],"names":[],"mappings":";;AAAA,+CAAmD;AAKnD,MAAM,8BAA8B,GAAkE;IACrG,EAAE,EAAE,0BAA0B;IAC9B,SAAS,EAAE,kBAAkB;IAC7B,IAAI,EAAE,6BAA6B;IAC/B,MAAM,EAAE,EACP;CACL,CAAA;AAED,uBAAc,CAAC,WAAW,EAAE,CAAC,WAAW,CAAC,8BAA8B,CAAC,CAAA;AAExE,kBAAe,8BAA8B,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"fieldClassMap.js","sourceRoot":"","sources":["../../../../src/.spruce/schemas/fields/fieldClassMap.ts"],"names":[],"mappings":";;AAAA,+CAAkD;AAKlD,kBAAe,sBAAa,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"fields.types.js","sourceRoot":"","sources":["../../../../src/.spruce/schemas/fields/fields.types.ts"],"names":[],"mappings":""}
@@ -1,8 +0,0 @@
1
- declare const valueTypes: {
2
- SpruceAgentUtils: {
3
- agentLoaderNotConfigured: {
4
- __latest: {};
5
- };
6
- };
7
- };
8
- export default valueTypes;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fieldClassMap_1 = __importDefault(require('./../fields/fieldClassMap.js'));
7
- const schemaTemplateItems = [{ "id": "agentLoaderNotConfigured", "namespace": "SpruceAgentUtils", "schema": { "namespace": "SpruceAgentUtils", "id": "agentLoaderNotConfigured", "name": "agent loader not configured", "fields": {} }, "nameReadable": "agent loader not configured", "nameCamel": "agentLoaderNotConfigured", "namePascal": "AgentLoaderNotConfigured", "isNested": false, "destinationDir": "#spruce/errors" }];
8
- // @ts-ignore
9
- const generateTypeLiteral = (definition, renderAs, importAs) => {
10
- const options = {
11
- language: 'ts',
12
- // @ts-ignore
13
- templateItems: schemaTemplateItems,
14
- globalNamespace: 'SpruceErrors',
15
- definition,
16
- importAs,
17
- renderAs
18
- };
19
- const FieldClass = fieldClassMap_1.default[definition.type];
20
- const details = FieldClass.generateTemplateDetails(options);
21
- return details.valueType;
22
- };
23
- const valueTypes = {
24
- "SpruceAgentUtils": {
25
- "agentLoaderNotConfigured": {
26
- "__latest": {},
27
- },
28
- },
29
- };
30
- exports.default = valueTypes;
31
- //# sourceMappingURL=valueType.tmp.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"valueType.tmp.js","sourceRoot":"","sources":["../../../../src/.spruce/schemas/tmp/valueType.tmp.ts"],"names":[],"mappings":";;;;;AAEA,yFAAgE;AAOhE,MAAM,mBAAmB,GAAG,CAAC,EAAC,IAAI,EAAC,0BAA0B,EAAC,WAAW,EAAC,kBAAkB,EAAC,QAAQ,EAAC,EAAC,WAAW,EAAC,kBAAkB,EAAC,IAAI,EAAC,0BAA0B,EAAC,MAAM,EAAC,6BAA6B,EAAC,QAAQ,EAAC,EAAE,EAAC,EAAC,cAAc,EAAC,6BAA6B,EAAC,WAAW,EAAC,0BAA0B,EAAC,YAAY,EAAC,0BAA0B,EAAC,UAAU,EAAC,KAAK,EAAC,gBAAgB,EAAC,gBAAgB,EAAC,CAAC,CAAA;AACxY,aAAa;AACb,MAAM,mBAAmB,GAAG,CAAC,UAA4B,EAAE,QAA0B,EAAE,QAAgB,EAAE,EAAE;IAC1G,MAAM,OAAO,GAAiD;QAC7D,QAAQ,EAAE,IAAI;QACd,aAAa;QACb,aAAa,EAAE,mBAAmB;QAClC,eAAe,EAAE,cAAc;QAC/B,UAAU;QACV,QAAQ;QACR,QAAQ;KACR,CAAA;IAED,MAAM,UAAU,GAAG,uBAAa,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IACjD,MAAM,OAAO,GAAG,UAAU,CAAC,uBAAuB,CACjD,OAAc,CACd,CAAA;IAED,OAAO,OAAO,CAAC,SAAS,CAAA;AACzB,CAAC,CAAA;AAGD,MAAM,UAAU,GAAG;IAClB,kBAAkB,EAAE;QACnB,0BAA0B,EAAE;YAC3B,UAAU,EAAC,EACV;SACD;KACD;CACD,CAAA;AAED,kBAAe,UAAU,CAAA"}
@@ -1,15 +0,0 @@
1
- {
2
- "scriptUpdater": {
3
- "skipped": []
4
- },
5
- "skipped": [
6
- "skill"
7
- ],
8
- "installed": [
9
- "test",
10
- "schema",
11
- "error",
12
- "permission",
13
- "event"
14
- ]
15
- }
@@ -1,13 +0,0 @@
1
- import { MercuryClient } from '@sprucelabs/mercury-client';
2
- export default class SpruceAgent implements AgentLoader {
3
- private static instance?;
4
- private client;
5
- private constructor();
6
- static setup(client: MercuryClient): void;
7
- static reset(): void;
8
- static getInstance(): SpruceAgent;
9
- getName(): Promise<string>;
10
- }
11
- export interface AgentLoader {
12
- getName(): Promise<string>;
13
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const SpruceError_1 = __importDefault(require('./errors/SpruceError.js'));
7
- class SpruceAgent {
8
- constructor(client) {
9
- this.client = client;
10
- }
11
- static setup(client) {
12
- this.instance = new SpruceAgent(client);
13
- }
14
- static reset() {
15
- delete this.instance;
16
- }
17
- static getInstance() {
18
- if (this.instance) {
19
- return this.instance;
20
- }
21
- throw new SpruceError_1.default({
22
- code: 'AGENT_LOADER_NOT_CONFIGURED',
23
- });
24
- }
25
- async getName() {
26
- const [{ name }] = await this.client.emitAndFlattenResponses('get-agent-name::v2020_12_25');
27
- return name;
28
- }
29
- }
30
- exports.default = SpruceAgent;
31
- //# sourceMappingURL=AgentLoader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AgentLoader.js","sourceRoot":"","sources":["../src/AgentLoader.ts"],"names":[],"mappings":";;;;;AACA,uEAA8C;AAE9C,MAAqB,WAAW;IAI5B,YAAoB,MAAqB;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,MAAqB;QACrC,IAAI,CAAC,QAAQ,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3C,CAAC;IAEM,MAAM,CAAC,KAAK;QACf,OAAO,IAAI,CAAC,QAAQ,CAAA;IACxB,CAAC;IAEM,MAAM,CAAC,WAAW;QACrB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,QAAQ,CAAA;QACxB,CAAC;QACD,MAAM,IAAI,qBAAW,CAAC;YAClB,IAAI,EAAE,6BAA6B;SACtC,CAAC,CAAA;IACN,CAAC;IAEM,KAAK,CAAC,OAAO;QAChB,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,uBAAuB,CACxD,6BAA6B,CAChC,CAAA;QAED,OAAO,IAAI,CAAA;IACf,CAAC;CACJ;AAhCD,8BAgCC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpruceAgent.js","sourceRoot":"","sources":["../src/SpruceAgent.ts"],"names":[],"mappings":";;;;;AACA,uEAA8C;AAE9C,MAAqB,WAAW;IAI5B,YAAoB,MAAqB;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,MAAqB;QACrC,IAAI,CAAC,QAAQ,GAAG,IAAI,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BAAa,EAAC,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;QACjC,mBAAM,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,kCAAkC,CAAC,CAAA;IACtE,CAAC;CACJ,CAAA;AAED,kBAAe,WAAW,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpruceError.js","sourceRoot":"","sources":["../../src/errors/SpruceError.ts"],"names":[],"mappings":";;;;;AAAA,8DAA+C;AAG/C,MAAqB,WAAY,SAAQ,eAA6B;IAClE,kDAAkD;IAC3C,eAAe;QAClB,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QACxB,IAAI,OAAO,CAAA;QACX,QAAQ,OAAO,EAAE,IAAI,EAAE,CAAC;YACpB,KAAK,6BAA6B;gBAC9B,OAAO,GAAG,2IAA2I,CAAA;gBACrJ,MAAK;YACT;gBACI,OAAO,GAAG,KAAK,CAAC,eAAe,EAAE,CAAA;QACzC,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,CAAC,eAAe;YACvC,CAAC,CAAC,OAAO,CAAC,eAAe;YACzB,CAAC,CAAC,OAAO,CAAA;QAEb,OAAO,WAAW,CAAA;IACtB,CAAC;CACJ;AAnBD,8BAmBC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"agentLoaderNotConfigured.builder.js","sourceRoot":"","sources":["../../src/errors/agentLoaderNotConfigured.builder.ts"],"names":[],"mappings":";;AAAA,+CAAqD;AAErD,kBAAe,IAAA,yBAAgB,EAAC;IAC5B,EAAE,EAAE,0BAA0B;IAC9B,IAAI,EAAE,6BAA6B;IACnC,MAAM,EAAE,EAAE;CACb,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6CAAsD;AAA7C,2HAAA,OAAO,OAAe;AAC/B,gDAA6B;AAC7B,6CAAsD;AAA7C,2HAAA,OAAO,OAAe"}