@far-world-labs/verblets 0.1.1 → 0.1.2
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/.cursor/launch.json +30 -0
- package/.cursor/settings.json +20 -0
- package/.github/workflows/branch-protection.yml +22 -0
- package/.github/workflows/ci.yml +117 -0
- package/.prettierrc +6 -0
- package/.release-it.json +4 -1
- package/.vscode/launch.json +31 -0
- package/AGENTS.md +220 -0
- package/DEVELOPING.md +105 -0
- package/README.md +671 -0
- package/eslint.config.js +80 -0
- package/package.json +28 -16
- package/scripts/generate-test/index.js +29 -3
- package/scripts/runner/index.js +26 -0
- package/scripts/simple-editor/index.js +29 -18
- package/scripts/summarize-files/index.js +28 -4
- package/src/chains/README.md +30 -0
- package/src/chains/anonymize/README.md +21 -0
- package/src/chains/anonymize/index.examples.js +75 -0
- package/src/chains/anonymize/index.js +121 -0
- package/src/chains/anonymize/index.spec.js +78 -0
- package/src/chains/bulk-central-tendency/index.examples.js +138 -0
- package/src/chains/bulk-central-tendency/index.js +91 -0
- package/src/chains/bulk-filter/README.md +21 -0
- package/src/chains/bulk-filter/index.examples.js +22 -0
- package/src/chains/bulk-filter/index.js +58 -0
- package/src/chains/bulk-filter/index.spec.js +38 -0
- package/src/chains/bulk-find/README.md +16 -0
- package/src/chains/bulk-find/index.examples.js +20 -0
- package/src/chains/bulk-find/index.js +30 -0
- package/src/chains/bulk-find/index.spec.js +26 -0
- package/src/chains/bulk-group/README.md +23 -0
- package/src/chains/bulk-group/index.examples.js +18 -0
- package/src/chains/bulk-group/index.js +34 -0
- package/src/chains/bulk-group/index.spec.js +41 -0
- package/src/chains/bulk-map/README.md +43 -0
- package/src/chains/bulk-map/index.examples.js +17 -0
- package/src/chains/bulk-map/index.js +86 -0
- package/src/chains/bulk-map/index.spec.js +44 -0
- package/src/chains/bulk-reduce/README.md +12 -0
- package/src/chains/bulk-reduce/index.examples.js +15 -0
- package/src/chains/bulk-reduce/index.js +13 -0
- package/src/chains/bulk-reduce/index.spec.js +25 -0
- package/src/chains/bulk-score/README.md +16 -0
- package/src/chains/bulk-score/bulk-score-result.json +18 -0
- package/src/chains/bulk-score/index.examples.js +22 -0
- package/src/chains/bulk-score/index.js +133 -0
- package/src/chains/bulk-score/index.spec.js +30 -0
- package/src/chains/category-samples/README.md +61 -0
- package/src/chains/category-samples/index.examples.js +103 -0
- package/src/chains/category-samples/index.js +134 -0
- package/src/chains/collect-terms/README.md +12 -0
- package/src/chains/collect-terms/index.examples.js +16 -0
- package/src/chains/collect-terms/index.js +44 -0
- package/src/chains/collect-terms/index.spec.js +25 -0
- package/src/chains/date/README.md +12 -0
- package/src/chains/date/index.examples.js +47 -0
- package/src/chains/date/index.js +74 -0
- package/src/chains/date/index.spec.js +62 -0
- package/src/chains/disambiguate/README.md +22 -0
- package/src/chains/disambiguate/disambiguate-meanings-result.json +16 -0
- package/src/chains/disambiguate/index.examples.js +18 -0
- package/src/chains/disambiguate/index.js +92 -0
- package/src/chains/disambiguate/index.spec.js +25 -0
- package/src/chains/dismantle/README.md +67 -0
- package/src/chains/dismantle/dismantle.examples.js +27 -0
- package/src/chains/dismantle/index.js +6 -17
- package/src/chains/dismantle/index.spec.js +1 -2
- package/src/chains/expect/README.md +171 -0
- package/src/chains/expect/index.examples.js +146 -0
- package/src/chains/expect/index.js +173 -0
- package/src/chains/expect/index.spec.js +324 -0
- package/src/chains/filter-ambiguous/README.md +11 -0
- package/src/chains/filter-ambiguous/index.examples.js +20 -0
- package/src/chains/filter-ambiguous/index.js +49 -0
- package/src/chains/filter-ambiguous/index.spec.js +31 -0
- package/src/chains/glossary/README.md +19 -0
- package/src/chains/glossary/index.examples.js +386 -0
- package/src/chains/glossary/index.js +75 -0
- package/src/chains/glossary/index.spec.js +19 -0
- package/src/chains/intersections/README.md +152 -0
- package/src/chains/intersections/index.examples.js +279 -0
- package/src/chains/intersections/index.js +366 -0
- package/src/chains/intersections/intersection-result.json +38 -0
- package/src/chains/list/index.examples.js +12 -16
- package/src/chains/list/index.js +106 -53
- package/src/chains/list/index.spec.js +3 -9
- package/src/chains/list/list-result.json +16 -0
- package/src/chains/llm-logger/README.md +208 -0
- package/src/chains/llm-logger/index.js +205 -0
- package/src/chains/llm-logger/index.spec.js +330 -0
- package/src/chains/questions/index.examples.js +2 -1
- package/src/chains/questions/index.js +14 -15
- package/src/chains/scan-js/index.js +6 -9
- package/src/chains/set-interval/README.md +81 -0
- package/src/chains/set-interval/index.examples.js +36 -0
- package/src/chains/set-interval/index.js +131 -0
- package/src/chains/set-interval/index.spec.js +70 -0
- package/src/chains/socratic/README.md +17 -0
- package/src/chains/socratic/index.js +64 -0
- package/src/chains/socratic/index.spec.js +24 -0
- package/src/chains/sort/index.examples.js +3 -7
- package/src/chains/sort/index.js +65 -15
- package/src/chains/sort/index.spec.js +5 -8
- package/src/chains/sort/sort-result.json +16 -0
- package/src/chains/summary-map/README.md +9 -1
- package/src/chains/summary-map/index.examples.js +9 -2
- package/src/chains/summary-map/index.js +43 -25
- package/src/chains/summary-map/index.spec.js +78 -3
- package/src/chains/test/index.js +9 -13
- package/src/chains/test-advice/index.js +4 -5
- package/src/chains/themes/README.md +20 -0
- package/src/chains/themes/index.examples.js +17 -0
- package/src/chains/themes/index.js +28 -0
- package/src/chains/themes/index.spec.js +19 -0
- package/src/chains/veiled-variants/index.examples.js +18 -0
- package/src/chains/veiled-variants/index.js +107 -0
- package/src/chains/veiled-variants/index.spec.js +40 -0
- package/src/constants/common.js +0 -2
- package/src/constants/models.js +172 -0
- package/src/index.js +178 -18
- package/src/json-schemas/README.md +13 -0
- package/src/json-schemas/index.js +8 -14
- package/src/json-schemas/schema-dot-org-photograph.json +11 -5
- package/src/json-schemas/schema-dot-org-place.json +78 -5
- package/src/lib/README.md +26 -0
- package/src/lib/bulk-filter/README.md +22 -0
- package/src/lib/bulk-filter/index.examples.js +27 -0
- package/src/lib/bulk-filter/index.js +63 -0
- package/src/lib/bulk-filter/index.spec.js +38 -0
- package/src/lib/bulk-find/README.md +18 -0
- package/src/lib/bulk-find/index.examples.js +19 -0
- package/src/lib/bulk-find/index.js +30 -0
- package/src/lib/bulk-find/index.spec.js +41 -0
- package/src/lib/chatgpt/index.js +63 -43
- package/src/lib/combinations/index.js +30 -0
- package/src/lib/combinations/index.spec.js +23 -0
- package/src/lib/functional/index.js +28 -0
- package/src/lib/logger-service/index.js +32 -0
- package/src/lib/parse-js-parts/index.js +9 -21
- package/src/lib/parse-llm-list/README.md +39 -0
- package/src/lib/parse-llm-list/index.js +54 -0
- package/src/lib/parse-llm-list/index.spec.js +59 -0
- package/src/lib/path-aliases/index.js +1 -3
- package/src/lib/path-aliases/index.spec.js +2 -8
- package/src/lib/pave/index.js +4 -4
- package/src/lib/pave/index.spec.js +6 -3
- package/src/lib/prompt-cache/index.js +14 -10
- package/src/lib/retry/index.js +11 -8
- package/src/lib/ring-buffer/README.md +460 -0
- package/src/lib/ring-buffer/index.js +1074 -0
- package/src/lib/search-best-first/city-walk.spec.js +37 -0
- package/src/lib/search-best-first/index.js +42 -11
- package/src/lib/search-best-first/index.spec.js +35 -0
- package/src/lib/search-js-files/index.js +21 -41
- package/src/lib/search-js-files/scan-file.js +10 -21
- package/src/lib/shorten-text/index.js +2 -7
- package/src/lib/shorten-text/index.spec.js +3 -3
- package/src/lib/strip-response/index.js +2 -7
- package/src/lib/template-replace/index.js +23 -0
- package/src/lib/template-replace/index.spec.js +60 -0
- package/src/lib/to-date/index.js +11 -0
- package/src/lib/to-number/index.js +1 -1
- package/src/lib/transcribe/index.js +4 -4
- package/src/prompts/README.md +3 -1
- package/src/prompts/as-object-with-schema.js +3 -8
- package/src/prompts/as-schema-org-text.js +10 -2
- package/src/prompts/code-features.js +1 -5
- package/src/prompts/constants.js +27 -27
- package/src/prompts/generate-collection.js +1 -1
- package/src/prompts/intent.js +11 -16
- package/src/prompts/select-from-threshold.js +1 -2
- package/src/prompts/sort.js +4 -8
- package/src/prompts/style.js +4 -7
- package/src/prompts/wrap-list.js +1 -4
- package/src/services/llm-model/global-overrides.spec.js +432 -0
- package/src/services/llm-model/index.js +234 -40
- package/src/services/llm-model/model.js +2 -2
- package/src/services/llm-model/negotiate.spec.js +447 -0
- package/src/services/redis/index.js +70 -7
- package/src/test/setup.js +20 -0
- package/src/verblets/README.md +26 -0
- package/src/verblets/auto/index.examples.js +12 -9
- package/src/verblets/auto/index.js +10 -10
- package/src/verblets/auto/index.spec.js +4 -6
- package/src/verblets/bool/README.md +36 -0
- package/src/verblets/bool/index.examples.js +53 -1
- package/src/verblets/bool/index.js +6 -9
- package/src/verblets/bool/index.spec.js +1 -3
- package/src/verblets/central-tendency/README.md +166 -0
- package/src/verblets/central-tendency/central-tendency-result.json +24 -0
- package/src/verblets/central-tendency/index.examples.js +196 -0
- package/src/verblets/central-tendency/index.js +171 -0
- package/src/verblets/central-tendency/index.spec.js +148 -0
- package/src/verblets/enum/index.examples.js +1 -4
- package/src/verblets/enum/index.js +7 -4
- package/src/verblets/expect/README.md +64 -0
- package/src/verblets/expect/index.examples.js +109 -0
- package/src/verblets/expect/index.js +75 -0
- package/src/verblets/expect/index.spec.js +127 -0
- package/src/verblets/intent/index.examples.js +84 -1
- package/src/verblets/intent/index.js +56 -68
- package/src/verblets/intersection/README.md +16 -0
- package/src/verblets/intersection/index.examples.js +89 -0
- package/src/verblets/intersection/index.js +84 -0
- package/src/verblets/intersection/index.spec.js +60 -0
- package/src/verblets/intersection/intersection-result.json +16 -0
- package/src/verblets/list-expand/README.md +10 -0
- package/src/verblets/list-expand/index.examples.js +14 -0
- package/src/verblets/list-expand/index.js +104 -0
- package/src/verblets/list-expand/index.spec.js +18 -0
- package/src/verblets/list-expand/list-expand-result.json +16 -0
- package/src/verblets/list-filter/README.md +22 -0
- package/src/verblets/list-filter/index.examples.js +26 -0
- package/src/verblets/list-filter/index.js +18 -0
- package/src/verblets/list-filter/index.spec.js +19 -0
- package/src/verblets/list-find/README.md +11 -0
- package/src/verblets/list-find/index.examples.js +15 -0
- package/src/verblets/list-find/index.js +17 -0
- package/src/verblets/list-find/index.spec.js +19 -0
- package/src/verblets/list-group/README.md +16 -0
- package/src/verblets/list-group/index.examples.js +16 -0
- package/src/verblets/list-group/index.js +112 -0
- package/src/verblets/list-group/index.spec.js +35 -0
- package/src/verblets/list-group/list-group-result.json +16 -0
- package/src/verblets/list-map/README.md +11 -0
- package/src/verblets/list-map/index.examples.js +15 -0
- package/src/verblets/list-map/index.js +26 -0
- package/src/verblets/list-map/index.spec.js +17 -0
- package/src/verblets/list-reduce/README.md +10 -0
- package/src/verblets/list-reduce/index.examples.js +14 -0
- package/src/verblets/list-reduce/index.js +21 -0
- package/src/verblets/list-reduce/index.spec.js +27 -0
- package/src/verblets/list-reduce/index.spec.jsx +27 -0
- package/src/verblets/name/README.md +15 -0
- package/src/verblets/name/index.examples.js +28 -0
- package/src/verblets/name/index.js +19 -0
- package/src/verblets/name/index.spec.js +33 -0
- package/src/verblets/name-similar-to/README.md +26 -0
- package/src/verblets/name-similar-to/index.examples.js +18 -0
- package/src/verblets/name-similar-to/index.js +20 -0
- package/src/verblets/name-similar-to/index.spec.js +13 -0
- package/src/verblets/number/index.examples.js +173 -7
- package/src/verblets/number/index.js +5 -2
- package/src/verblets/number/index.spec.js +1 -3
- package/src/verblets/number-with-units/index.examples.js +5 -1
- package/src/verblets/number-with-units/index.js +74 -9
- package/src/verblets/number-with-units/number-with-units-result.json +23 -0
- package/src/verblets/schema-org/index.examples.js +2 -7
- package/src/verblets/schema-org/index.js +32 -3
- package/src/verblets/sentiment/README.md +10 -0
- package/src/verblets/sentiment/index.examples.js +20 -0
- package/src/verblets/sentiment/index.js +9 -0
- package/src/verblets/sentiment/index.spec.js +20 -0
- package/src/verblets/to-object/index.js +10 -15
- package/src/verblets/to-object/index.spec.js +1 -4
- package/.eslintrc.json +0 -42
- package/docs/README.md +0 -41
- package/docs/babel.config.js +0 -3
- package/docs/blog/2019-05-28-first-blog-post.md +0 -12
- package/docs/blog/2019-05-29-long-blog-post.md +0 -44
- package/docs/blog/2021-08-01-mdx-blog-post.mdx +0 -20
- package/docs/blog/2021-08-26-welcome/docusaurus-plushie-banner.jpeg +0 -0
- package/docs/blog/2021-08-26-welcome/index.md +0 -25
- package/docs/blog/authors.yml +0 -17
- package/docs/docs/api/bool.md +0 -74
- package/docs/docs/api/search.md +0 -51
- package/docs/docs/intro.md +0 -47
- package/docs/docs/tutorial-basics/_category_.json +0 -8
- package/docs/docs/tutorial-basics/congratulations.md +0 -23
- package/docs/docs/tutorial-basics/create-a-blog-post.md +0 -34
- package/docs/docs/tutorial-basics/create-a-document.md +0 -57
- package/docs/docs/tutorial-basics/create-a-page.md +0 -43
- package/docs/docs/tutorial-basics/deploy-your-site.md +0 -31
- package/docs/docs/tutorial-basics/markdown-features.mdx +0 -152
- package/docs/docs/tutorial-extras/_category_.json +0 -7
- package/docs/docs/tutorial-extras/img/docsVersionDropdown.png +0 -0
- package/docs/docs/tutorial-extras/img/localeDropdown.png +0 -0
- package/docs/docs/tutorial-extras/manage-docs-versions.md +0 -55
- package/docs/docs/tutorial-extras/translate-your-site.md +0 -88
- package/docs/docusaurus.config.js +0 -120
- package/docs/package.json +0 -44
- package/docs/sidebars.js +0 -31
- package/docs/src/components/HomepageFeatures/index.js +0 -61
- package/docs/src/components/HomepageFeatures/styles.module.css +0 -11
- package/docs/src/css/custom.css +0 -30
- package/docs/src/pages/index.js +0 -43
- package/docs/src/pages/index.module.css +0 -23
- package/docs/src/pages/markdown-page.md +0 -7
- package/docs/static/.nojekyll +0 -0
- package/docs/static/img/docusaurus-social-card.jpg +0 -0
- package/docs/static/img/docusaurus.png +0 -0
- package/docs/static/img/favicon.ico +0 -0
- package/docs/static/img/logo.svg +0 -1
- package/docs/static/img/undraw_docusaurus_mountain.svg +0 -171
- package/docs/static/img/undraw_docusaurus_react.svg +0 -170
- package/docs/static/img/undraw_docusaurus_tree.svg +0 -40
- package/src/constants/openai.js +0 -65
- /package/{.vite.config.examples.js → .vitest.config.examples.js} +0 -0
- /package/{.vite.config.js → .vitest.config.js} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
# Verblets
|
|
2
|
+
|
|
3
|
+
Verblets is a library of AI-powered utilities that transform natural language and structured data into reliable, structured outputs. Each function uses language model intelligence while constraining outputs to limit hallucination and ensure software reliability.
|
|
4
|
+
|
|
5
|
+
## Repository Guide
|
|
6
|
+
|
|
7
|
+
### Quick Links
|
|
8
|
+
|
|
9
|
+
- [Chains](./src/chains/) - AI-powered workflows and operations
|
|
10
|
+
- [Verblets](./src/verblets/) - Core AI utility functions
|
|
11
|
+
- [Library Helpers](./src/lib/) - Utility functions and wrappers
|
|
12
|
+
- [Prompts](./src/prompts/) - Reusable prompt templates
|
|
13
|
+
- [JSON Schemas](./src/json-schemas/) - Data validation schemas
|
|
14
|
+
|
|
15
|
+
## Verblets
|
|
16
|
+
|
|
17
|
+
### Primitives
|
|
18
|
+
|
|
19
|
+
Primitive verblets extract basic data types from natural language with high reliability. They constrain LLM outputs to prevent hallucination while handling the complexity of human expression.
|
|
20
|
+
|
|
21
|
+
- [bool](./src/verblets/bool) - interpret text as true/false decisions
|
|
22
|
+
- [enum](./src/verblets/enum) - map text to predefined options
|
|
23
|
+
- [number](./src/verblets/number) - extract numeric values from text
|
|
24
|
+
- [number-with-units](./src/verblets/number-with-units) - parse numbers with units and conversions
|
|
25
|
+
- [date](./src/chains/date) - return Date objects from natural language prompts
|
|
26
|
+
|
|
27
|
+
### Lists
|
|
28
|
+
|
|
29
|
+
List operations transform, filter, and organize collections using natural language criteria. They handle both small lists with individual verblets and large datasets with batch processing chains.
|
|
30
|
+
|
|
31
|
+
- [bulk-map](./src/chains/bulk-map) - process long lists in retryable batches
|
|
32
|
+
- [bulk-reduce](./src/chains/bulk-reduce) - reduce long lists in manageable chunks
|
|
33
|
+
- [bulk-find](./src/chains/bulk-find) - locate the best match in large datasets
|
|
34
|
+
- [bulk-group](./src/chains/bulk-group) - group large datasets efficiently
|
|
35
|
+
- [bulk-filter](./src/chains/bulk-filter) - filter huge lists in batches
|
|
36
|
+
- [intersections](./src/chains/intersections) - find comprehensive intersections for all combinations
|
|
37
|
+
- [list](./src/chains/list) - generate contextual lists from prompts
|
|
38
|
+
- [list-map](./src/verblets/list-map) - transform each item in a list
|
|
39
|
+
- [list-reduce](./src/verblets/list-reduce) - combine list items using custom logic
|
|
40
|
+
- [list-find](./src/verblets/list-find) - pick the single best item from a list
|
|
41
|
+
- [list-filter](./src/verblets/list-filter) - filter lists with natural language criteria
|
|
42
|
+
- [list-group](./src/verblets/list-group) - categorize list items into groups
|
|
43
|
+
- [list-expand](./src/verblets/list-expand) - generate additional similar items
|
|
44
|
+
- [intersection](./src/verblets/intersection) - describe common traits between items
|
|
45
|
+
- [sort](./src/chains/sort) - order lists by any describable criteria
|
|
46
|
+
- [bulk-score](./src/chains/bulk-score) - score lists with calibrated examples
|
|
47
|
+
|
|
48
|
+
### Content
|
|
49
|
+
|
|
50
|
+
Content utilities generate, transform, and analyze text while maintaining structure and meaning. They excel at creative tasks, system analysis, and privacy-aware text processing.
|
|
51
|
+
|
|
52
|
+
- [anonymize](./src/chains/anonymize) - scrub personal details from text
|
|
53
|
+
- [collect-terms](./src/chains/collect-terms) - extract difficult vocabulary
|
|
54
|
+
- [dismantle](./src/chains/dismantle) - break systems into components
|
|
55
|
+
- [disambiguate](./src/chains/disambiguate) - resolve ambiguous word meanings using context
|
|
56
|
+
- [filter-ambiguous](./src/chains/filter-ambiguous) - find and rank unclear terms for disambiguation
|
|
57
|
+
- [name](./src/verblets/name) - name something from a definition or description
|
|
58
|
+
- [name-similar-to](./src/verblets/name-similar-to) - suggest short names that match a style
|
|
59
|
+
- [questions](./src/chains/questions) - produce clarifying questions
|
|
60
|
+
- [schema-org](./src/verblets/schema-org) - create schema.org objects
|
|
61
|
+
- [socratic](./src/chains/socratic) - explore assumptions using a Socratic dialogue
|
|
62
|
+
- [summary-map](./src/chains/summary-map) - summarize a collection
|
|
63
|
+
- [themes](./src/chains/themes) - identify themes in text
|
|
64
|
+
- [category-samples](./src/chains/category-samples) - generate diverse examples for any category
|
|
65
|
+
- [to-object](./src/verblets/to-object) - convert descriptions to structured objects
|
|
66
|
+
- [veiled-variants](./src/chains/veiled-variants) - rephrase sensitive queries safely
|
|
67
|
+
|
|
68
|
+
### Utility Operations
|
|
69
|
+
|
|
70
|
+
Utility operations provide meta-functionality like automatic tool selection, intent parsing, and context compression. They're essential for building intelligent systems that can adapt and scale.
|
|
71
|
+
|
|
72
|
+
- [auto](./src/verblets/auto) - automatically select the best verblet for a task
|
|
73
|
+
- [expect](./src/verblets/expect) - simple LLM assertions
|
|
74
|
+
- [expect chain](./src/chains/expect) - assert things about data with LLM reasoning
|
|
75
|
+
- [intent](./src/verblets/intent) - extract user intent and structured parameters
|
|
76
|
+
- [sentiment](./src/verblets/sentiment) - detect emotional tone of text
|
|
77
|
+
- [summary-map](./src/chains/summary-map) - store self-resizing hash table values. Useful for fixed-sized contexts.
|
|
78
|
+
- [set-interval](./src/chains/set-interval) - Conversational scheduler
|
|
79
|
+
|
|
80
|
+
### Codebase
|
|
81
|
+
|
|
82
|
+
Codebase utilities analyze, test, and improve code quality using AI reasoning. They provide insights that traditional static analysis tools miss by understanding context and intent.
|
|
83
|
+
|
|
84
|
+
- [scan-js](./src/chains/scan-js) - analyze JavaScript code quality
|
|
85
|
+
- [test](./src/chains/test) - run AI-driven software tests
|
|
86
|
+
- [test-advice](./src/chains/test-advice) - get feedback on test coverage
|
|
87
|
+
|
|
88
|
+
## Library Helpers
|
|
89
|
+
|
|
90
|
+
- [chatgpt](./src/lib/chatgpt) - OpenAI ChatGPT wrapper
|
|
91
|
+
- [prompt-cache](./src/lib/prompt-cache) - cache prompts and responses
|
|
92
|
+
- [retry](./src/lib/retry) - retry asynchronous calls
|
|
93
|
+
- [search-best-first](./src/lib/search-best-first) - best-first search algorithm
|
|
94
|
+
- [search-js-files](./src/lib/search-js-files) - scan JavaScript sources
|
|
95
|
+
- [combinations](./src/lib/combinations) - generate array combinations
|
|
96
|
+
- [shorten-text](./src/lib/shorten-text) - shorten text using a model
|
|
97
|
+
- [strip-numeric](./src/lib/strip-numeric) - remove non-digit characters
|
|
98
|
+
- [strip-response](./src/lib/strip-response) - clean up model responses
|
|
99
|
+
- [to-bool](./src/lib/to-bool) - parse text to boolean
|
|
100
|
+
- [to-enum](./src/lib/to-enum) - parse text to enum values
|
|
101
|
+
- [to-number](./src/lib/to-number) - parse text to numbers
|
|
102
|
+
- [to-number-with-units](./src/lib/to-number-with-units) - parse numbers with units
|
|
103
|
+
- [to-date](./src/lib/to-date) - parse text to JavaScript Date objects
|
|
104
|
+
- [transcribe](./src/lib/transcribe) - microphone transcription via Whisper
|
|
105
|
+
|
|
106
|
+
## Example: Intelligent Customer Support System
|
|
107
|
+
|
|
108
|
+
This example shows how verblets enable building systems that understand context, make nuanced decisions, and adapt to complex real-world scenarios - capabilities that would be nearly impossible with traditional programming approaches.
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
import {
|
|
112
|
+
intent,
|
|
113
|
+
sentiment,
|
|
114
|
+
bool,
|
|
115
|
+
enum,
|
|
116
|
+
toObject,
|
|
117
|
+
anonymize,
|
|
118
|
+
questions,
|
|
119
|
+
sort,
|
|
120
|
+
listFilter,
|
|
121
|
+
summaryMap,
|
|
122
|
+
} from 'verblets';
|
|
123
|
+
|
|
124
|
+
// Intelligent customer support system that handles complex, contextual requests
|
|
125
|
+
async function handleCustomerRequest(customerMessage, customerHistory, productCatalog) {
|
|
126
|
+
// 1. Understand what the customer actually wants
|
|
127
|
+
const customerIntent = await intent({
|
|
128
|
+
text: customerMessage,
|
|
129
|
+
operations: [
|
|
130
|
+
{ name: 'refund-request', parameters: { reason: 'string', orderNumber: 'string?' } },
|
|
131
|
+
{ name: 'product-inquiry', parameters: { productType: 'string', feature: 'string?' } },
|
|
132
|
+
{ name: 'technical-support', parameters: { issue: 'string', urgency: 'string' } },
|
|
133
|
+
{ name: 'complaint', parameters: { category: 'string', severity: 'string' } },
|
|
134
|
+
],
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// 2. Assess emotional state and urgency
|
|
138
|
+
const emotionalState = await sentiment(customerMessage);
|
|
139
|
+
const isUrgent = await bool(`Is this customer request urgent? ${customerMessage}`);
|
|
140
|
+
|
|
141
|
+
// 3. Determine appropriate response strategy
|
|
142
|
+
const responseStrategy = await enum(customerMessage, {
|
|
143
|
+
immediate_escalation: 'Customer is very upset, escalate to human agent',
|
|
144
|
+
detailed_help: 'Customer needs comprehensive assistance',
|
|
145
|
+
quick_resolution: 'Simple issue that can be resolved quickly',
|
|
146
|
+
educational: 'Customer needs to understand how something works',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// 4. Generate contextual follow-up questions
|
|
150
|
+
const clarifyingQuestions = await questions(
|
|
151
|
+
`Customer says: "${customerMessage}". What should we ask to help them better?`
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// 5. Find relevant products/solutions from catalog
|
|
155
|
+
const relevantProducts = await listFilter(
|
|
156
|
+
productCatalog,
|
|
157
|
+
`Products that might solve: ${
|
|
158
|
+
customerIntent.parameters.issue || customerIntent.parameters.productType
|
|
159
|
+
}`
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// 6. Prioritize solutions by customer context
|
|
163
|
+
const prioritizedSolutions = await sort(
|
|
164
|
+
relevantProducts,
|
|
165
|
+
`by relevance to ${emotionalState} customer with ${customerIntent.intent.operation} request`
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
// 7. Create anonymized case summary for training
|
|
169
|
+
const caseSummary = await anonymize(
|
|
170
|
+
`Customer ${customerIntent.intent.operation}: ${customerMessage}.
|
|
171
|
+
History: ${customerHistory}. Resolution: ${prioritizedSolutions[0]}`
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// 8. Structure the complete response
|
|
175
|
+
const response = await toObject(
|
|
176
|
+
`
|
|
177
|
+
Customer needs ${customerIntent.intent.operation} help.
|
|
178
|
+
They are ${emotionalState} and ${isUrgent ? 'urgent' : 'not urgent'}.
|
|
179
|
+
Best approach: ${responseStrategy}.
|
|
180
|
+
Top solution: ${prioritizedSolutions[0]?.name}
|
|
181
|
+
`,
|
|
182
|
+
{
|
|
183
|
+
type: 'object',
|
|
184
|
+
properties: {
|
|
185
|
+
intent: { type: 'string' },
|
|
186
|
+
urgency: { type: 'string' },
|
|
187
|
+
emotion: { type: 'string' },
|
|
188
|
+
strategy: { type: 'string' },
|
|
189
|
+
recommendedSolution: { type: 'string' },
|
|
190
|
+
followUpQuestions: { type: 'array' },
|
|
191
|
+
},
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
...response,
|
|
197
|
+
followUpQuestions: clarifyingQuestions.slice(0, 3),
|
|
198
|
+
anonymizedCase: caseSummary,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Usage: Handle a complex customer scenario
|
|
203
|
+
const result = await handleCustomerRequest(
|
|
204
|
+
"I'm really frustrated! I ordered your premium headphones 2 weeks ago for my daughter's birthday tomorrow and they still haven't arrived. The tracking says 'processing' but I paid for 2-day shipping. This is completely unacceptable and I want my money back immediately!",
|
|
205
|
+
'Previous orders: 3 successful deliveries, 1 late delivery complaint resolved',
|
|
206
|
+
[
|
|
207
|
+
{
|
|
208
|
+
name: 'Premium Wireless Headphones',
|
|
209
|
+
category: 'audio',
|
|
210
|
+
features: ['noise-canceling', 'wireless'],
|
|
211
|
+
},
|
|
212
|
+
{ name: 'Express Shipping Upgrade', category: 'service', features: ['priority', 'tracking'] },
|
|
213
|
+
{ name: 'Gift Card', category: 'compensation', features: ['flexible', 'immediate'] },
|
|
214
|
+
]
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
/* Returns something like:
|
|
218
|
+
{
|
|
219
|
+
intent: "refund-request",
|
|
220
|
+
urgency: "high",
|
|
221
|
+
emotion: "frustrated",
|
|
222
|
+
strategy: "immediate_escalation",
|
|
223
|
+
recommendedSolution: "Express Shipping Upgrade",
|
|
224
|
+
followUpQuestions: [
|
|
225
|
+
"What's your order number so I can track this immediately?",
|
|
226
|
+
"Would you like us to expedite a replacement for tomorrow delivery?",
|
|
227
|
+
"How can we make this right for your daughter's birthday?"
|
|
228
|
+
],
|
|
229
|
+
anonymizedCase: "Customer refund-request: Customer frustrated about delayed premium headphones order for child's birthday..."
|
|
230
|
+
}
|
|
231
|
+
*/
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
This system demonstrates capabilities that would require thousands of lines of traditional code and extensive machine learning expertise:
|
|
235
|
+
|
|
236
|
+
- **Contextual understanding** of customer emotions and intent
|
|
237
|
+
- **Dynamic decision making** based on multiple factors
|
|
238
|
+
- **Adaptive questioning** that changes based on the situation
|
|
239
|
+
- **Intelligent prioritization** of solutions
|
|
240
|
+
- **Privacy-aware data handling** for compliance
|
|
241
|
+
- **Structured output** that integrates with existing systems
|
|
242
|
+
|
|
243
|
+
<<<<<<< HEAD
|
|
244
|
+
With verblets, complex AI-powered workflows become as simple as calling functions.
|
|
245
|
+
=======
|
|
246
|
+
- **list** - Generate contextual lists
|
|
247
|
+
```javascript
|
|
248
|
+
await list("potential failure points in our microservices architecture");
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
- **intent** - Understand user intentions and extract structured data
|
|
252
|
+
```javascript
|
|
253
|
+
// Define what operations your system can handle
|
|
254
|
+
const operations = [
|
|
255
|
+
{
|
|
256
|
+
name: "book-flight",
|
|
257
|
+
parameters: {
|
|
258
|
+
destination: "string",
|
|
259
|
+
date: "string",
|
|
260
|
+
class: "string"
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "find-song",
|
|
265
|
+
parameters: {
|
|
266
|
+
lyrics: "string",
|
|
267
|
+
artist: "string?"
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
];
|
|
271
|
+
|
|
272
|
+
// It understands flight booking requests
|
|
273
|
+
const flightRequest = await intent({
|
|
274
|
+
text: "I need a business class flight to Tokyo next Friday",
|
|
275
|
+
operations
|
|
276
|
+
});
|
|
277
|
+
/* Returns:
|
|
278
|
+
{
|
|
279
|
+
"queryText": "I need a business class flight to Tokyo next Friday",
|
|
280
|
+
"intent": {
|
|
281
|
+
"operation": "book-flight",
|
|
282
|
+
"displayName": "Book Flight"
|
|
283
|
+
},
|
|
284
|
+
"parameters": {
|
|
285
|
+
"destination": "Tokyo",
|
|
286
|
+
"date": "next Friday",
|
|
287
|
+
"class": "business"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
- **auto** - Use function calling to select and prepare operations
|
|
293
|
+
```javascript
|
|
294
|
+
// First, we have our available functions defined as schemas
|
|
295
|
+
const availableFunctions = [
|
|
296
|
+
{
|
|
297
|
+
"name": "bool",
|
|
298
|
+
"description": "Answer yes/no questions about facts or situations",
|
|
299
|
+
"parameters": {
|
|
300
|
+
"type": "object",
|
|
301
|
+
"properties": {
|
|
302
|
+
"text": {
|
|
303
|
+
"type": "string",
|
|
304
|
+
"description": "The question to answer"
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"name": "list",
|
|
311
|
+
"description": "Generate lists of relevant items",
|
|
312
|
+
"parameters": {
|
|
313
|
+
"type": "object",
|
|
314
|
+
"properties": {
|
|
315
|
+
"text": {
|
|
316
|
+
"type": "string",
|
|
317
|
+
"description": "What to list"
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
// ... many more function definitions ...
|
|
323
|
+
];
|
|
324
|
+
|
|
325
|
+
// When someone has an urgent question
|
|
326
|
+
const result = await auto(
|
|
327
|
+
"Help! My dog just ate an avocado! Is this dangerous?"
|
|
328
|
+
);
|
|
329
|
+
/* First, auto selects the appropriate function:
|
|
330
|
+
{
|
|
331
|
+
"name": "bool", // Recognizes this needs a yes/no answer
|
|
332
|
+
"arguments": {
|
|
333
|
+
"text": "Help! My dog just ate an avocado! Is this dangerous?"
|
|
334
|
+
},
|
|
335
|
+
"functionArgsAsArray": [
|
|
336
|
+
{
|
|
337
|
+
"text": "Help! My dog just ate an avocado! Is this dangerous?"
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
// Then it automatically runs the selected function internally, passing arguments it extracts
|
|
344
|
+
const answer = await bool(result.arguments.text);
|
|
345
|
+
// Returns: true (yes, it can be dangerous)
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
- **questions** - Explore topics through intelligent question generation
|
|
349
|
+
```javascript
|
|
350
|
+
|
|
351
|
+
const investigation = await questions(
|
|
352
|
+
"Why isn't my houseplant thriving?",
|
|
353
|
+
{
|
|
354
|
+
searchBreadth: 0.7, // Explore more broadly (0-1)
|
|
355
|
+
shouldStop: (q, all) => all.length > 20 // Custom stopping condition
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
/* Returns targeted diagnostic questions:
|
|
359
|
+
[
|
|
360
|
+
"Which direction does the window face?",
|
|
361
|
+
"Are the leaves turning yellow or brown?",
|
|
362
|
+
"Is the soil staying wet for long periods?",
|
|
363
|
+
"Are there any visible pests on the leaves?",
|
|
364
|
+
"When was it last repotted?",
|
|
365
|
+
"Is there good drainage in the pot?",
|
|
366
|
+
"What's the humidity level in the room?",
|
|
367
|
+
// ... continues until stopping condition ...
|
|
368
|
+
]
|
|
369
|
+
*/
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
- **shorten-text** - Intelligently compress text while preserving meaning
|
|
373
|
+
```javascript
|
|
374
|
+
// Shorten long content while keeping key information
|
|
375
|
+
const story = `Once upon a time, in a bustling city called Metropolis,
|
|
376
|
+
there lived a young programmer named Ada. She spent her days writing
|
|
377
|
+
elegant code and her nights dreaming of artificial intelligence.
|
|
378
|
+
One day, while debugging a particularly tricky neural network,
|
|
379
|
+
she discovered something extraordinary...`;
|
|
380
|
+
|
|
381
|
+
const shortened = await shortenText(story, {
|
|
382
|
+
targetTokenCount: 20,
|
|
383
|
+
minCharsToRemove: 15
|
|
384
|
+
});
|
|
385
|
+
/* Returns:
|
|
386
|
+
"Once upon a time, in Metropolis, a programmer named Ada
|
|
387
|
+
spent her days writing code... discovered something extraordinary"
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
// Preserve structure while reducing size
|
|
391
|
+
const documentation = `# API Reference
|
|
392
|
+
## Authentication
|
|
393
|
+
All requests must include an API key in the header.
|
|
394
|
+
The key should be prefixed with 'Bearer '.
|
|
395
|
+
|
|
396
|
+
## Rate Limiting
|
|
397
|
+
Requests are limited to 100 per minute.
|
|
398
|
+
Exceeding this will result in a 429 response.
|
|
399
|
+
|
|
400
|
+
## Endpoints
|
|
401
|
+
GET /users - Retrieve user list
|
|
402
|
+
POST /users - Create new user
|
|
403
|
+
DELETE /users/{id} - Remove user`;
|
|
404
|
+
|
|
405
|
+
const compact = await shortenText(documentation, {
|
|
406
|
+
targetTokenCount: 30,
|
|
407
|
+
minCharsToRemove: 20
|
|
408
|
+
});
|
|
409
|
+
/* Returns:
|
|
410
|
+
"# API Reference
|
|
411
|
+
## Authentication
|
|
412
|
+
All requests need API key... 'Bearer '
|
|
413
|
+
|
|
414
|
+
## Rate Limiting
|
|
415
|
+
100 per minute... 429 response
|
|
416
|
+
|
|
417
|
+
## Endpoints
|
|
418
|
+
GET /users...DELETE /users/{id}"
|
|
419
|
+
*/
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
- **bulk-map** - Map over lists in retryable batches using the `listMap` verblet
|
|
423
|
+
```javascript
|
|
424
|
+
import { bulkMap } from './src/index.js';
|
|
425
|
+
|
|
426
|
+
const gadgets = [
|
|
427
|
+
'solar-powered flashlight',
|
|
428
|
+
'quantum laptop',
|
|
429
|
+
'smart refrigerator',
|
|
430
|
+
// ...more items
|
|
431
|
+
];
|
|
432
|
+
const results = await bulkMap(
|
|
433
|
+
gadgets,
|
|
434
|
+
'Give each item a catchphrase worthy of a blockbuster commercial',
|
|
435
|
+
{ chunkSize: 5, maxAttempts: 2 }
|
|
436
|
+
);
|
|
437
|
+
// results[0] === 'Illuminate your world with the sun'
|
|
438
|
+
// results[1] === 'Computing beyond limits'
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
- **bulk-reduce** - Reduce long lists sequentially using `listReduce`
|
|
442
|
+
```javascript
|
|
443
|
+
import bulkReduce from './src/chains/bulk-reduce/index.js';
|
|
444
|
+
|
|
445
|
+
const logLines = [
|
|
446
|
+
'User logged in',
|
|
447
|
+
'User viewed dashboard',
|
|
448
|
+
'User logged out'
|
|
449
|
+
];
|
|
450
|
+
const summary = await bulkReduce(logLines, 'Summarize the events');
|
|
451
|
+
// e.g. 'User session: login, dashboard view and logout'
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
<<<<<<< HEAD
|
|
455
|
+
**bulk-partition** - Discover the best categories and group large lists consistently
|
|
456
|
+
```javascript
|
|
457
|
+
import bulkPartition from './src/chains/bulk-partition/index.js';
|
|
458
|
+
|
|
459
|
+
const feedback = [
|
|
460
|
+
'Great interface and onboarding',
|
|
461
|
+
'Price is a bit steep',
|
|
462
|
+
'Love the mobile app',
|
|
463
|
+
'Needs more integrations'
|
|
464
|
+
];
|
|
465
|
+
const result = await bulkPartition(
|
|
466
|
+
feedback,
|
|
467
|
+
'Is each line praise, criticism, or a feature request?',
|
|
468
|
+
{ chunkSize: 2, topN: 3 }
|
|
469
|
+
);
|
|
470
|
+
// {
|
|
471
|
+
// praise: ['Great interface and onboarding', 'Love the mobile app'],
|
|
472
|
+
// criticism: ['Price is a bit steep'],
|
|
473
|
+
// 'feature request': ['Needs more integrations']
|
|
474
|
+
// }
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
- **themes** - Extract recurring themes from text
|
|
478
|
+
```javascript
|
|
479
|
+
const mainThemes = await themes(longReport, { topN: 3 });
|
|
480
|
+
// ['strategy', 'market challenges', 'team morale']
|
|
481
|
+
```
|
|
482
|
+
=======
|
|
483
|
+
- **bulk-find** - Search lists in batches using `listFind`
|
|
484
|
+
```javascript
|
|
485
|
+
import bulkFind, { bulkFindRetry } from './src/lib/bulk-find/index.js';
|
|
486
|
+
|
|
487
|
+
const diaryEntries = [
|
|
488
|
+
'Hiked up the mountains today and saw breathtaking views',
|
|
489
|
+
'Visited the local market and tried a spicy stew',
|
|
490
|
+
'Spotted penguins playing on the beach this morning'
|
|
491
|
+
];
|
|
492
|
+
const match = await bulkFindRetry(diaryEntries, 'mentions penguins', {
|
|
493
|
+
chunkSize: 2,
|
|
494
|
+
maxAttempts: 2
|
|
495
|
+
});
|
|
496
|
+
// => 'Spotted penguins playing on the beach this morning'
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
>>>>>>> f71abac (Restore eslint disable comment)
|
|
500
|
+
- **search-best-first** - Intelligently explore solution spaces
|
|
501
|
+
```javascript
|
|
502
|
+
// Find the best recipe adjustments when ingredients are missing
|
|
503
|
+
const search = new BestFirstSearch({
|
|
504
|
+
initialState: {
|
|
505
|
+
recipe: "Classic Tiramisu",
|
|
506
|
+
missing: ["mascarpone cheese", "ladyfingers"],
|
|
507
|
+
available: ["cream cheese", "pound cake", "whipped cream"]
|
|
508
|
+
},
|
|
509
|
+
goalTest: state => state.substitutions.complete && state.flavor.preserved,
|
|
510
|
+
heuristic: state => state.flavor.similarity
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
const path = await search.findPath();
|
|
514
|
+
/* Returns sequence of steps:
|
|
515
|
+
[
|
|
516
|
+
{
|
|
517
|
+
action: "substitute mascarpone",
|
|
518
|
+
details: "Mix 8oz cream cheese with 1/4 cup whipped cream",
|
|
519
|
+
confidence: 0.85
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
action: "substitute ladyfingers",
|
|
523
|
+
details: "Slice pound cake, toast until crisp, soak in coffee",
|
|
524
|
+
confidence: 0.75
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
action: "adjust ratios",
|
|
528
|
+
details: "Increase coffee soak time to 45 seconds for pound cake",
|
|
529
|
+
confidence: 0.9
|
|
530
|
+
}
|
|
531
|
+
]
|
|
532
|
+
*/
|
|
533
|
+
|
|
534
|
+
// Or find the optimal way to refactor complex code
|
|
535
|
+
const refactorPath = await new BestFirstSearch({
|
|
536
|
+
initialState: {
|
|
537
|
+
file: "src/legacy-parser.js",
|
|
538
|
+
metrics: {
|
|
539
|
+
complexity: 85,
|
|
540
|
+
coverage: 0.4,
|
|
541
|
+
maintainability: "D"
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
goalTest: state =>
|
|
545
|
+
state.metrics.complexity < 30 &&
|
|
546
|
+
state.metrics.coverage > 0.8 &&
|
|
547
|
+
state.metrics.maintainability === "A",
|
|
548
|
+
heuristic: state =>
|
|
549
|
+
(1 / state.metrics.complexity) *
|
|
550
|
+
state.metrics.coverage *
|
|
551
|
+
(state.metrics.maintainability === "A" ? 1 : 0.5)
|
|
552
|
+
}).findPath();
|
|
553
|
+
/* Returns optimal refactoring sequence:
|
|
554
|
+
[
|
|
555
|
+
{
|
|
556
|
+
action: "extract function",
|
|
557
|
+
target: "parseNestedBlocks()",
|
|
558
|
+
benefit: "Reduces complexity by 40%"
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
action: "add unit tests",
|
|
562
|
+
coverage: ["error handling", "edge cases"],
|
|
563
|
+
benefit: "Coverage increases to 85%"
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
action: "implement strategy pattern",
|
|
567
|
+
components: ["BlockParser", "InlineParser"],
|
|
568
|
+
benefit: "Maintainability improves to grade A"
|
|
569
|
+
}
|
|
570
|
+
]
|
|
571
|
+
*/
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
- **test-advice** - Get comprehensive testing and code quality insights
|
|
575
|
+
```javascript
|
|
576
|
+
// Get deep analysis of your code's test coverage and quality
|
|
577
|
+
const insights = await testAdvice("src/payment-processor.js");
|
|
578
|
+
/* Returns array of findings across multiple dimensions:
|
|
579
|
+
[
|
|
580
|
+
{
|
|
581
|
+
"name": "Boundary Testing",
|
|
582
|
+
"expected": "Handle zero-amount transactions",
|
|
583
|
+
"saw": "No validation for $0.00 payments in processPayment()",
|
|
584
|
+
"isSuccess": false
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
"name": "Success Scenarios",
|
|
588
|
+
"expected": "Processes standard credit card payment",
|
|
589
|
+
"saw": "Correctly handles Visa/MC format: line 47 validateCard()",
|
|
590
|
+
"isSuccess": true
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
"name": "Clean Code",
|
|
594
|
+
"expected": "Single responsibility in transaction logging",
|
|
595
|
+
"saw": "logPayment() mixing business logic with logging: line 92",
|
|
596
|
+
"isSuccess": false
|
|
597
|
+
},
|
|
598
|
+
// ... analyzes across 8 dimensions:
|
|
599
|
+
// - Boundary cases
|
|
600
|
+
// - Success scenarios
|
|
601
|
+
// - Failure modes
|
|
602
|
+
// - Potential defects
|
|
603
|
+
// - Best practices
|
|
604
|
+
// - Clean code principles
|
|
605
|
+
// - Code quality
|
|
606
|
+
// - Refactoring opportunities
|
|
607
|
+
]
|
|
608
|
+
*/
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
- **veiled-variants** - Mask sensitive queries with safer alternatives
|
|
612
|
+
```javascript
|
|
613
|
+
const alternatives = await veiledVariants({
|
|
614
|
+
prompt: "If pigeons are government spies, how can I ask for counter-surveillance tips without sounding paranoid?"
|
|
615
|
+
});
|
|
616
|
+
/* Returns 15 reframed queries */
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
- **scan-js** - Analyze code for quality and maintainability
|
|
620
|
+
```javascript
|
|
621
|
+
// Analyze your codebase for maintainability
|
|
622
|
+
const analysis = await scanJs({
|
|
623
|
+
entry: "src/app.js",
|
|
624
|
+
features: "maintainability"
|
|
625
|
+
});
|
|
626
|
+
/* Returns analysis of each function:
|
|
627
|
+
{
|
|
628
|
+
"src/app.js:::handlePayment": {
|
|
629
|
+
"complexity": "low",
|
|
630
|
+
"documentation": "well-documented",
|
|
631
|
+
"sideEffects": "isolated to database calls",
|
|
632
|
+
"errorHandling": "comprehensive",
|
|
633
|
+
"testability": "high"
|
|
634
|
+
},
|
|
635
|
+
"src/app.js:::validateInput": {
|
|
636
|
+
"complexity": "medium",
|
|
637
|
+
"documentation": "needs improvement",
|
|
638
|
+
"sideEffects": "pure function",
|
|
639
|
+
"errorHandling": "basic validation only",
|
|
640
|
+
"testability": "high"
|
|
641
|
+
}
|
|
642
|
+
// ... continues for all functions ...
|
|
643
|
+
}
|
|
644
|
+
*/
|
|
645
|
+
|
|
646
|
+
// Focus on specific quality aspects
|
|
647
|
+
const security = await scanJs({
|
|
648
|
+
entry: "src/auth/",
|
|
649
|
+
features: "security"
|
|
650
|
+
});
|
|
651
|
+
/* Returns security-focused analysis:
|
|
652
|
+
{
|
|
653
|
+
"src/auth/login.js:::hashPassword": {
|
|
654
|
+
"inputValidation": "sanitizes all inputs",
|
|
655
|
+
"cryptography": "uses current best practices",
|
|
656
|
+
"dataExposure": "no sensitive data in logs",
|
|
657
|
+
"authentication": "implements rate limiting"
|
|
658
|
+
}
|
|
659
|
+
// ... continues for all security-relevant functions ...
|
|
660
|
+
}
|
|
661
|
+
*/
|
|
662
|
+
```
|
|
663
|
+
>>>>>>> 01eb5cf (Add themes chain for dual reduce)
|
|
664
|
+
|
|
665
|
+
## Contributing
|
|
666
|
+
|
|
667
|
+
Help us explore what's possible when we rebuild software primitives with intelligence at their core.
|
|
668
|
+
|
|
669
|
+
## License
|
|
670
|
+
|
|
671
|
+
All Rights Reserved - Far World Labs
|