File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,26 @@ describe('hash', async () => {
4747 expect ( metadata1 . hash ) . not . toBe ( metadata3 . hash )
4848 } )
4949
50+ it ( 'always returns ast (serialized fragments)' , async ( ) => {
51+ const prompt = 'This is a prompt'
52+
53+ const metadata = await scan ( { prompt } )
54+ expect ( metadata . ast ) . toEqual ( {
55+ start : 0 ,
56+ end : 16 ,
57+ type : 'Fragment' ,
58+ children : [
59+ {
60+ start : 0 ,
61+ end : 16 ,
62+ type : 'Text' ,
63+ raw : 'This is a prompt' ,
64+ data : 'This is a prompt' ,
65+ } ,
66+ ] ,
67+ } )
68+ } )
69+
5070 it ( 'includes the content from referenced tags into account when calculating the hash' , async ( ) => {
5171 const parent = 'This is the parent prompt. <prompt path="child" /> The end.'
5272 const child1 = 'ABCDEFG'
Original file line number Diff line number Diff line change @@ -174,6 +174,7 @@ export class Scan {
174174 ...( scopeContext . onlyPredefinedVariables ?? new Set ( [ ] ) ) ,
175175 ] ) ,
176176 hash,
177+ ast : fragment ,
177178 resolvedPrompt,
178179 config : this . config ?? { } ,
179180 errors : this . errors ,
Original file line number Diff line number Diff line change 11import CompileError from '$promptl/error/error'
2+ import { Fragment } from '$promptl/index'
23
34import { Message } from './message'
45
@@ -12,6 +13,7 @@ export type Conversation = {
1213export type ConversationMetadata = {
1314 hash : string
1415 resolvedPrompt : string
16+ ast : Fragment
1517 config : Config
1618 errors : CompileError [ ]
1719 parameters : Set < string > // Variables used in the prompt that have not been defined in runtime
You can’t perform that action at this time.
0 commit comments