@svara/prompts 0.1.0 → 0.2.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.
Files changed (2) hide show
  1. package/README.md +50 -8
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # prompt
1
+ # prompts
2
2
 
3
3
  A tiny, ergonomic tagged-template utility for assembling LLM prompts in TypeScript.
4
4
 
@@ -25,12 +25,17 @@ The library is intentionally small: a single tagged template (`prompt` / `ai`) p
25
25
 
26
26
  ## Install
27
27
 
28
- Copy `prompt.ts` into your project. No runtime dependencies.
28
+ ```sh
29
+ bun add @svara/prompts
30
+ # or: npm i @svara/prompts
31
+ ```
32
+
33
+ Zero runtime dependencies.
29
34
 
30
35
  ## Quick start
31
36
 
32
37
  ```ts
33
- import { prompt, ai } from './prompt'
38
+ import { prompt, ai } from '@svara/prompts'
34
39
 
35
40
  const p = ai`
36
41
  Summarize the following text in one sentence.
@@ -82,17 +87,36 @@ After assembly the output is cleaned up:
82
87
  6. **Primitives** — `String(value).trim()`.
83
88
  7. **Nullish / `false`** — empty string.
84
89
 
85
- ### `JsonValue<T>`
90
+ ### `JsonValue<T>` and plain objects
86
91
 
87
- Wrap a value to force JSON-fence rendering even when it would otherwise be treated as a primitive or skipped:
92
+ Any plain object is auto-rendered as a JSON code fence no wrapper required. `JsonValue<T>` is only needed when you want to force a specific value (e.g. an array, or a primitive that would otherwise be stringified) into the JSON-fence path.
88
93
 
89
94
  ```ts
90
- import { JsonValue, ai } from './prompt'
95
+ import { JsonValue, ai } from '@svara/prompts'
96
+
97
+ ai`
98
+ Config:
99
+ ${{ retries: 3, timeoutMs: 5_000 }}
100
+ `
101
+ // Config:
102
+ // ```json
103
+ // {
104
+ // "retries": 3,
105
+ // "timeoutMs": 5000
106
+ // }
107
+ // ```
91
108
 
92
109
  ai`
93
110
  Config:
94
111
  ${new JsonValue({ retries: 3, timeoutMs: 5_000 })}
95
112
  `
113
+ // Config:
114
+ // ```json
115
+ // {
116
+ // "retries": 3,
117
+ // "timeoutMs": 5000
118
+ // }
119
+ // ```
96
120
  ```
97
121
 
98
122
  ### Zod (and other schema libs)
@@ -101,6 +125,7 @@ Any object with a `toJSONSchema()` method is rendered as its schema. Zod v4 is t
101
125
 
102
126
  ```ts
103
127
  import { z } from 'zod'
128
+ import { ai } from '@svara/prompts'
104
129
 
105
130
  const UserSchema = z.object({ id: z.string(), name: z.string() })
106
131
 
@@ -108,6 +133,17 @@ ai`
108
133
  Return data matching this schema:
109
134
  ${UserSchema}
110
135
  `
136
+ // Return data matching this schema:
137
+ // ```json
138
+ // {
139
+ // "type": "object",
140
+ // "properties": {
141
+ // "id": { "type": "string" },
142
+ // "name": { "type": "string" }
143
+ // },
144
+ // "required": ["id", "name"]
145
+ // }
146
+ // ```
111
147
  ```
112
148
 
113
149
  ### Custom render protocol
@@ -115,7 +151,7 @@ ai`
115
151
  For your own classes, opt in via the exported `renderPrompt` symbol:
116
152
 
117
153
  ```ts
118
- import { renderPrompt, ai } from './prompt'
154
+ import { renderPrompt, ai } from '@svara/prompts'
119
155
 
120
156
  class Document {
121
157
  constructor(public title: string, public body: string) {}
@@ -131,8 +167,14 @@ class Document {
131
167
  ai`
132
168
  Read the document below and answer the question.
133
169
 
134
- ${new Document('Onboarding', '...')}
170
+ ${new Document('Onboarding', 'Welcome to the team.\nRead the handbook.')}
135
171
  `
172
+ // Read the document below and answer the question.
173
+ //
174
+ // # Onboarding
175
+ //
176
+ // Welcome to the team.
177
+ // Read the handbook.
136
178
  ```
137
179
 
138
180
  The value returned from `[renderPrompt]()` is itself a `PromptValue` and gets re-flattened — so you can return a string, an array, another `ai\`\`` result, or a `JsonValue`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svara/prompts",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Tiny ergonomic tagged-template utility for assembling LLM prompts",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",