@wabot-dev/framework 0.1.0-beta.11 → 0.1.0-beta.13

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 (61) hide show
  1. package/dist/src/ai/claude/ClaudeChatBotAdapter.js +115 -0
  2. package/dist/src/channels/whatsapp/WhatsApp.js +2 -2
  3. package/dist/src/channels/whatsapp/WhatsAppSender.js +10 -1
  4. package/dist/src/channels/whatsapp/WhatsAppSenderByCloudApi.js +3 -9
  5. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +6 -11
  6. package/dist/src/core/{Persistent.js → Entity.js} +24 -9
  7. package/dist/src/core/Storable.js +8 -0
  8. package/dist/src/core/chat/Chat.js +2 -2
  9. package/dist/src/core/chat/ChatItem.js +2 -2
  10. package/dist/src/core/user/User.js +2 -2
  11. package/dist/src/error/CustomError.js +1 -0
  12. package/dist/src/index.d.ts +250 -181
  13. package/dist/src/index.js +13 -9
  14. package/dist/src/node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.js +221 -0
  15. package/dist/src/node_modules/@anthropic-ai/sdk/client.js +540 -0
  16. package/dist/src/node_modules/@anthropic-ai/sdk/core/api-promise.js +74 -0
  17. package/dist/src/node_modules/@anthropic-ai/sdk/core/error.js +100 -0
  18. package/dist/src/node_modules/@anthropic-ai/sdk/core/pagination.js +119 -0
  19. package/dist/src/node_modules/@anthropic-ai/sdk/core/resource.js +8 -0
  20. package/dist/src/node_modules/@anthropic-ai/sdk/core/streaming.js +283 -0
  21. package/dist/src/node_modules/@anthropic-ai/sdk/internal/constants.js +16 -0
  22. package/dist/src/node_modules/@anthropic-ai/sdk/internal/decoders/jsonl.js +37 -0
  23. package/dist/src/node_modules/@anthropic-ai/sdk/internal/decoders/line.js +110 -0
  24. package/dist/src/node_modules/@anthropic-ai/sdk/internal/detect-platform.js +159 -0
  25. package/dist/src/node_modules/@anthropic-ai/sdk/internal/errors.js +37 -0
  26. package/dist/src/node_modules/@anthropic-ai/sdk/internal/headers.js +71 -0
  27. package/dist/src/node_modules/@anthropic-ai/sdk/internal/parse.js +53 -0
  28. package/dist/src/node_modules/@anthropic-ai/sdk/internal/request-options.js +11 -0
  29. package/dist/src/node_modules/@anthropic-ai/sdk/internal/shims.js +86 -0
  30. package/dist/src/node_modules/@anthropic-ai/sdk/internal/to-file.js +94 -0
  31. package/dist/src/node_modules/@anthropic-ai/sdk/internal/tslib.js +14 -0
  32. package/dist/src/node_modules/@anthropic-ai/sdk/internal/uploads.js +113 -0
  33. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/bytes.js +27 -0
  34. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/env.js +19 -0
  35. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/log.js +82 -0
  36. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/path.js +76 -0
  37. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/sleep.js +4 -0
  38. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/uuid.js +16 -0
  39. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/values.js +48 -0
  40. package/dist/src/node_modules/@anthropic-ai/sdk/lib/BetaMessageStream.js +588 -0
  41. package/dist/src/node_modules/@anthropic-ai/sdk/lib/MessageStream.js +582 -0
  42. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/beta.js +19 -0
  43. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/files.js +120 -0
  44. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.js +202 -0
  45. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.js +85 -0
  46. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/models.js +58 -0
  47. package/dist/src/node_modules/@anthropic-ai/sdk/resources/completions.js +21 -0
  48. package/dist/src/node_modules/@anthropic-ai/sdk/resources/messages/batches.js +151 -0
  49. package/dist/src/node_modules/@anthropic-ai/sdk/resources/messages/messages.js +71 -0
  50. package/dist/src/node_modules/@anthropic-ai/sdk/resources/models.js +43 -0
  51. package/dist/src/node_modules/@anthropic-ai/sdk/version.js +3 -0
  52. package/dist/src/pre-made/repository/chat/ram/RamChatRepository.js +1 -1
  53. package/dist/src/repository/pg/PgCrudRepository.js +2 -2
  54. package/dist/src/repository/pg/PgRepositoryBase.js +2 -2
  55. package/dist/src/rest-controller/metadata/@middleware.js +16 -0
  56. package/dist/src/rest-controller/metadata/RestControllerMetadataStore.js +13 -0
  57. package/dist/src/rest-controller/runRestControllers.js +30 -22
  58. package/dist/src/server/prepareChatContainer.js +2 -2
  59. package/dist/src/validation/metadata/@isModel.js +18 -0
  60. package/dist/src/validation/validators/validateModel.js +2 -6
  61. package/package.json +2 -1
@@ -0,0 +1,19 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ /**
3
+ * Read an environment variable.
4
+ *
5
+ * Trims beginning and trailing whitespace.
6
+ *
7
+ * Will return undefined if the environment variable doesn't exist or cannot be accessed.
8
+ */
9
+ const readEnv = (env) => {
10
+ if (typeof globalThis.process !== 'undefined') {
11
+ return globalThis.process.env?.[env]?.trim() ?? undefined;
12
+ }
13
+ if (typeof globalThis.Deno !== 'undefined') {
14
+ return globalThis.Deno.env?.get?.(env)?.trim();
15
+ }
16
+ return undefined;
17
+ };
18
+
19
+ export { readEnv };
@@ -0,0 +1,82 @@
1
+ import { hasOwn } from './values.js';
2
+
3
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
4
+ const levelNumbers = {
5
+ off: 0,
6
+ error: 200,
7
+ warn: 300,
8
+ info: 400,
9
+ debug: 500,
10
+ };
11
+ const parseLogLevel = (maybeLevel, sourceName, client) => {
12
+ if (!maybeLevel) {
13
+ return undefined;
14
+ }
15
+ if (hasOwn(levelNumbers, maybeLevel)) {
16
+ return maybeLevel;
17
+ }
18
+ loggerFor(client).warn(`${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(Object.keys(levelNumbers))}`);
19
+ return undefined;
20
+ };
21
+ function noop() { }
22
+ function makeLogFn(fnLevel, logger, logLevel) {
23
+ if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {
24
+ return noop;
25
+ }
26
+ else {
27
+ // Don't wrap logger functions, we want the stacktrace intact!
28
+ return logger[fnLevel].bind(logger);
29
+ }
30
+ }
31
+ const noopLogger = {
32
+ error: noop,
33
+ warn: noop,
34
+ info: noop,
35
+ debug: noop,
36
+ };
37
+ let cachedLoggers = /* @__PURE__ */ new WeakMap();
38
+ function loggerFor(client) {
39
+ const logger = client.logger;
40
+ const logLevel = client.logLevel ?? 'off';
41
+ if (!logger) {
42
+ return noopLogger;
43
+ }
44
+ const cachedLogger = cachedLoggers.get(logger);
45
+ if (cachedLogger && cachedLogger[0] === logLevel) {
46
+ return cachedLogger[1];
47
+ }
48
+ const levelLogger = {
49
+ error: makeLogFn('error', logger, logLevel),
50
+ warn: makeLogFn('warn', logger, logLevel),
51
+ info: makeLogFn('info', logger, logLevel),
52
+ debug: makeLogFn('debug', logger, logLevel),
53
+ };
54
+ cachedLoggers.set(logger, [logLevel, levelLogger]);
55
+ return levelLogger;
56
+ }
57
+ const formatRequestDetails = (details) => {
58
+ if (details.options) {
59
+ details.options = { ...details.options };
60
+ delete details.options['headers']; // redundant + leaks internals
61
+ }
62
+ if (details.headers) {
63
+ details.headers = Object.fromEntries((details.headers instanceof Headers ? [...details.headers] : Object.entries(details.headers)).map(([name, value]) => [
64
+ name,
65
+ (name.toLowerCase() === 'x-api-key' ||
66
+ name.toLowerCase() === 'authorization' ||
67
+ name.toLowerCase() === 'cookie' ||
68
+ name.toLowerCase() === 'set-cookie') ?
69
+ '***'
70
+ : value,
71
+ ]));
72
+ }
73
+ if ('retryOfRequestLogID' in details) {
74
+ if (details.retryOfRequestLogID) {
75
+ details.retryOf = details.retryOfRequestLogID;
76
+ }
77
+ delete details.retryOfRequestLogID;
78
+ }
79
+ return details;
80
+ };
81
+
82
+ export { formatRequestDetails, loggerFor, parseLogLevel };
@@ -0,0 +1,76 @@
1
+ import { AnthropicError } from '../../core/error.js';
2
+
3
+ /**
4
+ * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
5
+ *
6
+ * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
7
+ * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
8
+ * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
9
+ * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
10
+ */
11
+ function encodeURIPath(str) {
12
+ return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
13
+ }
14
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
15
+ const createPathTagFunction = (pathEncoder = encodeURIPath) => function path(statics, ...params) {
16
+ // If there are no params, no processing is needed.
17
+ if (statics.length === 1)
18
+ return statics[0];
19
+ let postPath = false;
20
+ const invalidSegments = [];
21
+ const path = statics.reduce((previousValue, currentValue, index) => {
22
+ if (/[?#]/.test(currentValue)) {
23
+ postPath = true;
24
+ }
25
+ const value = params[index];
26
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
27
+ if (index !== params.length &&
28
+ (value == null ||
29
+ (typeof value === 'object' &&
30
+ // handle values from other realms
31
+ value.toString ===
32
+ Object.getPrototypeOf(Object.getPrototypeOf(value.hasOwnProperty ?? EMPTY) ?? EMPTY)
33
+ ?.toString))) {
34
+ encoded = value + '';
35
+ invalidSegments.push({
36
+ start: previousValue.length + currentValue.length,
37
+ length: encoded.length,
38
+ error: `Value of type ${Object.prototype.toString
39
+ .call(value)
40
+ .slice(8, -1)} is not a valid path parameter`,
41
+ });
42
+ }
43
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
44
+ }, '');
45
+ const pathOnly = path.split(/[?#]/, 1)[0];
46
+ const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
47
+ let match;
48
+ // Find all invalid segments
49
+ while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
50
+ invalidSegments.push({
51
+ start: match.index,
52
+ length: match[0].length,
53
+ error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
54
+ });
55
+ }
56
+ invalidSegments.sort((a, b) => a.start - b.start);
57
+ if (invalidSegments.length > 0) {
58
+ let lastEnd = 0;
59
+ const underline = invalidSegments.reduce((acc, segment) => {
60
+ const spaces = ' '.repeat(segment.start - lastEnd);
61
+ const arrows = '^'.repeat(segment.length);
62
+ lastEnd = segment.start + segment.length;
63
+ return acc + spaces + arrows;
64
+ }, '');
65
+ throw new AnthropicError(`Path parameters result in path with invalid segments:\n${invalidSegments
66
+ .map((e) => e.error)
67
+ .join('\n')}\n${path}\n${underline}`);
68
+ }
69
+ return path;
70
+ };
71
+ /**
72
+ * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
73
+ */
74
+ const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
75
+
76
+ export { createPathTagFunction, encodeURIPath, path };
@@ -0,0 +1,4 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
3
+
4
+ export { sleep };
@@ -0,0 +1,16 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ /**
3
+ * https://stackoverflow.com/a/2117523
4
+ */
5
+ let uuid4 = function () {
6
+ const { crypto } = globalThis;
7
+ if (crypto?.randomUUID) {
8
+ uuid4 = crypto.randomUUID.bind(crypto);
9
+ return crypto.randomUUID();
10
+ }
11
+ const u8 = new Uint8Array(1);
12
+ const randomByte = crypto ? () => crypto.getRandomValues(u8)[0] : () => (Math.random() * 0xff) & 0xff;
13
+ return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => (+c ^ (randomByte() & (15 >> (+c / 4)))).toString(16));
14
+ };
15
+
16
+ export { uuid4 };
@@ -0,0 +1,48 @@
1
+ import { AnthropicError } from '../../core/error.js';
2
+
3
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
4
+ // https://url.spec.whatwg.org/#url-scheme-string
5
+ const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
6
+ const isAbsoluteURL = (url) => {
7
+ return startsWithSchemeRegexp.test(url);
8
+ };
9
+ let isArray = (val) => ((isArray = Array.isArray), isArray(val));
10
+ let isReadonlyArray = isArray;
11
+ /** Returns an object if the given value isn't an object, otherwise returns as-is */
12
+ function maybeObj(x) {
13
+ if (typeof x !== 'object') {
14
+ return {};
15
+ }
16
+ return x ?? {};
17
+ }
18
+ // https://stackoverflow.com/a/34491287
19
+ function isEmptyObj(obj) {
20
+ if (!obj)
21
+ return true;
22
+ for (const _k in obj)
23
+ return false;
24
+ return true;
25
+ }
26
+ // https://eslint.org/docs/latest/rules/no-prototype-builtins
27
+ function hasOwn(obj, key) {
28
+ return Object.prototype.hasOwnProperty.call(obj, key);
29
+ }
30
+ const validatePositiveInteger = (name, n) => {
31
+ if (typeof n !== 'number' || !Number.isInteger(n)) {
32
+ throw new AnthropicError(`${name} must be an integer`);
33
+ }
34
+ if (n < 0) {
35
+ throw new AnthropicError(`${name} must be a positive integer`);
36
+ }
37
+ return n;
38
+ };
39
+ const safeJSON = (text) => {
40
+ try {
41
+ return JSON.parse(text);
42
+ }
43
+ catch (err) {
44
+ return undefined;
45
+ }
46
+ };
47
+
48
+ export { hasOwn, isAbsoluteURL, isArray, isEmptyObj, isReadonlyArray, maybeObj, safeJSON, validatePositiveInteger };