@bedrockio/ai 0.9.4 → 0.9.6

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/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.9.5
2
+
3
+ - Export all clients.
4
+ - Error if template directory incorrect.
5
+
1
6
  ## 0.9.4
2
7
 
3
8
  - Bumped yada dev version.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_fs_1 = require("node:fs");
3
4
  const templates_1 = require("@bedrockio/templates");
4
5
  const code_js_1 = require("./utils/code.js");
5
6
  const json_js_1 = require("./utils/json.js");
@@ -13,6 +14,13 @@ class BaseClient {
13
14
  this.renderer = new templates_1.TemplateRenderer({
14
15
  dir: options.templates,
15
16
  });
17
+ this.assertTemplatesDir();
18
+ }
19
+ assertTemplatesDir() {
20
+ const { templates } = this.options;
21
+ if (templates && !(0, node_fs_1.existsSync)(templates)) {
22
+ throw new Error(`Directory not found: ${templates}`);
23
+ }
16
24
  }
17
25
  // Public
18
26
  /**
@@ -110,7 +118,8 @@ class BaseClient {
110
118
  getFilteredMessages(options) {
111
119
  const { messages = [] } = options;
112
120
  return messages.filter((message) => {
113
- return message.content.trim();
121
+ const trimmed = message.content.trim();
122
+ return trimmed && trimmed !== '.';
114
123
  });
115
124
  }
116
125
  // Protected
@@ -236,12 +245,14 @@ class BaseClient {
236
245
  }
237
246
  if (result.length === 1 && !result[0].content) {
238
247
  // If a single user input is passed and is nullish, coerce it to a
239
- // single space. Combined with getFilteredMessages below this allows
248
+ // single period. Combined with getFilteredMessages below this allows
240
249
  // a chatbot the ability to "speak first" by prompting it with empty
241
250
  // content. The empty message will be filtered out of the final result
242
- // appearing as if the chatbot went first. Note empty string will also
243
- // fail here hence the single space.
244
- result[0].content = ' ';
251
+ // appearing as if the chatbot went first.
252
+ // Note that:
253
+ // GPT will fail on an empty string but on whitespace
254
+ // Anthropic will fail on all whitespace
255
+ result[0].content = '.';
245
256
  }
246
257
  return result;
247
258
  }
package/dist/cjs/index.js CHANGED
@@ -3,12 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.McpServer = void 0;
6
+ exports.XAiClient = exports.OpenAiClient = exports.GoogleClient = exports.AnthropicClient = exports.McpServer = void 0;
7
7
  exports.createClient = createClient;
8
8
  const anthropic_js_1 = require("./anthropic.js");
9
+ Object.defineProperty(exports, "AnthropicClient", { enumerable: true, get: function () { return anthropic_js_1.AnthropicClient; } });
9
10
  const google_js_1 = require("./google.js");
11
+ Object.defineProperty(exports, "GoogleClient", { enumerable: true, get: function () { return google_js_1.GoogleClient; } });
10
12
  const openai_js_1 = require("./openai.js");
13
+ Object.defineProperty(exports, "OpenAiClient", { enumerable: true, get: function () { return openai_js_1.OpenAiClient; } });
11
14
  const xai_js_1 = require("./xai.js");
15
+ Object.defineProperty(exports, "XAiClient", { enumerable: true, get: function () { return xai_js_1.XAiClient; } });
12
16
  var McpServer_js_1 = require("./McpServer.js");
13
17
  Object.defineProperty(exports, "McpServer", { enumerable: true, get: function () { return __importDefault(McpServer_js_1).default; } });
14
18
  function createClient(options = {}) {
@@ -1,3 +1,4 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { TemplateRenderer } from '@bedrockio/templates';
2
3
  import { parseCode } from './utils/code.js';
3
4
  import { createMessageExtractor } from './utils/json.js';
@@ -11,6 +12,13 @@ export default class BaseClient {
11
12
  this.renderer = new TemplateRenderer({
12
13
  dir: options.templates,
13
14
  });
15
+ this.assertTemplatesDir();
16
+ }
17
+ assertTemplatesDir() {
18
+ const { templates } = this.options;
19
+ if (templates && !existsSync(templates)) {
20
+ throw new Error(`Directory not found: ${templates}`);
21
+ }
14
22
  }
15
23
  // Public
16
24
  /**
@@ -108,7 +116,8 @@ export default class BaseClient {
108
116
  getFilteredMessages(options) {
109
117
  const { messages = [] } = options;
110
118
  return messages.filter((message) => {
111
- return message.content.trim();
119
+ const trimmed = message.content.trim();
120
+ return trimmed && trimmed !== '.';
112
121
  });
113
122
  }
114
123
  // Protected
@@ -234,12 +243,14 @@ export default class BaseClient {
234
243
  }
235
244
  if (result.length === 1 && !result[0].content) {
236
245
  // If a single user input is passed and is nullish, coerce it to a
237
- // single space. Combined with getFilteredMessages below this allows
246
+ // single period. Combined with getFilteredMessages below this allows
238
247
  // a chatbot the ability to "speak first" by prompting it with empty
239
248
  // content. The empty message will be filtered out of the final result
240
- // appearing as if the chatbot went first. Note empty string will also
241
- // fail here hence the single space.
242
- result[0].content = ' ';
249
+ // appearing as if the chatbot went first.
250
+ // Note that:
251
+ // GPT will fail on an empty string but on whitespace
252
+ // Anthropic will fail on all whitespace
253
+ result[0].content = '.';
243
254
  }
244
255
  return result;
245
256
  }
package/dist/esm/index.js CHANGED
@@ -24,3 +24,4 @@ export function createClient(options = {}) {
24
24
  throw new Error(`Unknown platform "${platform}".`);
25
25
  }
26
26
  }
27
+ export { AnthropicClient, GoogleClient, OpenAiClient, XAiClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/ai",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "description": "Bedrock wrapper for common AI chatbots.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -2,6 +2,7 @@ export default class BaseClient {
2
2
  constructor(options: any);
3
3
  options: any;
4
4
  renderer: TemplateRenderer;
5
+ assertTemplatesDir(): void;
5
6
  /**
6
7
  * Interpolates vars into the provided template as instructions and runs the
7
8
  * prompt.
@@ -1 +1 @@
1
- {"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../src/BaseClient.js"],"names":[],"mappings":"AAKA;IACE,0BASC;IARC,aAIC;IACD,2BAEE;IAKJ;;;;;OAKG;IACH,gBAFW,aAAa,gBAiCvB;IAED;;;;;OAKG;IACH,gBAHW,aAAa,GAAG,aAAa,gCAsDvC;IAED;;;;OAIG;IACH,wBAFW,MAAM,OAIhB;IAED,uCAKC;IAID,8BAGC;IAED,8BAGC;IAED,qCAGC;IAED;;OAEG;IACH,0CAGC;IAED;;OAEG;IACH,oDAIC;IAED;;OAEG;IACH,oDAIC;IAID;;OAEG;IACH,oCAOC;IAED;;;MAeC;IAED,4CAiDC;IAED,uCAkCC;IAED;;;MA4BC;IAED,uDAWC;IAED,kDAMC;CACF;;;;;WAIa,MAAM;kBACN,MAAM;;;;cACN,aAAa,EAAE;;;;YACf,MAAM;;;;YACN,OAAO;;;;;;;;aAEP,MAAM,GAAG,MAAM;;;;;;;;;;;sBAOf,MAAM;;;UAKN,QAAQ,GAAG,MAAM,GAAG,WAAW;aAC/B,MAAM;;iCA/Wa,sBAAsB"}
1
+ {"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../src/BaseClient.js"],"names":[],"mappings":"AAOA;IACE,0BAUC;IATC,aAIC;IACD,2BAEE;IAIJ,2BAKC;IAID;;;;;OAKG;IACH,gBAFW,aAAa,gBAiCvB;IAED;;;;;OAKG;IACH,gBAHW,aAAa,GAAG,aAAa,gCAsDvC;IAED;;;;OAIG;IACH,wBAFW,MAAM,OAIhB;IAED,uCAMC;IAID,8BAGC;IAED,8BAGC;IAED,qCAGC;IAED;;OAEG;IACH,0CAGC;IAED;;OAEG;IACH,oDAIC;IAED;;OAEG;IACH,oDAIC;IAID;;OAEG;IACH,oCAOC;IAED;;;MAeC;IAED,4CAiDC;IAED,uCAoCC;IAED;;;MA4BC;IAED,uDAWC;IAED,kDAMC;CACF;;;;;WAIa,MAAM;kBACN,MAAM;;;;cACN,aAAa,EAAE;;;;YACf,MAAM;;;;YACN,OAAO;;;;;;;;aAEP,MAAM,GAAG,MAAM;;;;;;;;;;;sBAOf,MAAM;;;UAKN,QAAQ,GAAG,MAAM,GAAG,WAAW;aAC/B,MAAM;;iCA1Xa,sBAAsB"}
package/types/index.d.ts CHANGED
@@ -3,4 +3,6 @@ export { default as McpServer } from "./McpServer.js";
3
3
  import { AnthropicClient } from './anthropic.js';
4
4
  import { GoogleClient } from './google.js';
5
5
  import { OpenAiClient } from './openai.js';
6
+ import { XAiClient } from './xai.js';
7
+ export { AnthropicClient, GoogleClient, OpenAiClient, XAiClient };
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAMA,0FAkBC;;gCAxB+B,gBAAgB;6BACnB,aAAa;6BACb,aAAa"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAMA,0FAkBC;;gCAxB+B,gBAAgB;6BACnB,aAAa;6BACb,aAAa;0BAChB,UAAU"}