@modular-prompt/core 0.1.9
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/LICENSE +21 -0
- package/README.md +63 -0
- package/dist/compile.d.ts +10 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +173 -0
- package/dist/compile.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/merge.d.ts +10 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +94 -0
- package/dist/merge.js.map +1 -0
- package/dist/types.d.ts +138 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 otolab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @modular-prompt/core
|
|
2
|
+
|
|
3
|
+
プロンプトモジュールフレームワークのコアパッケージ。
|
|
4
|
+
|
|
5
|
+
## 📚 ドキュメント
|
|
6
|
+
|
|
7
|
+
詳細は[ドキュメント](https://github.com/otolab/modular-prompt/tree/main/docs)を参照してください。
|
|
8
|
+
|
|
9
|
+
## インストール
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @modular-prompt/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 基本的な使用方法
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { compile, merge, createContext } from '@modular-prompt/core';
|
|
19
|
+
import type { PromptModule } from '@modular-prompt/core';
|
|
20
|
+
|
|
21
|
+
// Context型定義
|
|
22
|
+
interface MyContext {
|
|
23
|
+
inputs?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// プロセスモジュール(処理方法を定義)
|
|
27
|
+
const processModule: PromptModule<MyContext> = {
|
|
28
|
+
methodology: ['データを処理する'],
|
|
29
|
+
inputs: [(ctx) => ctx.inputs || '']
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ユーザーモジュール(タスクを定義)
|
|
33
|
+
const userModule = {
|
|
34
|
+
objective: ['タスクの目的'],
|
|
35
|
+
instructions: ['具体的な指示']
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// マージしてContextを取得
|
|
39
|
+
const merged = merge(processModule, userModule);
|
|
40
|
+
const context = createContext(merged);
|
|
41
|
+
context.inputs = 'データ';
|
|
42
|
+
|
|
43
|
+
// コンパイル
|
|
44
|
+
const compiled = compile(merged, context);
|
|
45
|
+
// compiled: CompiledPrompt
|
|
46
|
+
// {
|
|
47
|
+
// instructions: SectionElement[] // 指示セクション群
|
|
48
|
+
// data: SectionElement[] // データセクション群
|
|
49
|
+
// output: SectionElement[] // 出力セクション群
|
|
50
|
+
// metadata?: { outputSchema } // メタデータ
|
|
51
|
+
// }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 主要な機能
|
|
55
|
+
|
|
56
|
+
- **PromptModule**: 再利用可能なプロンプトテンプレート
|
|
57
|
+
- **compile**: モジュールを実行可能な形式に変換
|
|
58
|
+
- **merge**: 複数のモジュールを合成
|
|
59
|
+
- **createContext**: マージ済みモジュールから型安全なContextを取得
|
|
60
|
+
|
|
61
|
+
## ライセンス
|
|
62
|
+
|
|
63
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PromptModule, CompiledPrompt } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* モジュールとコンテキストからプロンプトをコンパイル
|
|
4
|
+
*/
|
|
5
|
+
export declare function compile<TContext = any>(module: PromptModule<TContext>, context?: TContext): CompiledPrompt;
|
|
6
|
+
/**
|
|
7
|
+
* コンテキストを作成するヘルパー関数
|
|
8
|
+
*/
|
|
9
|
+
export declare function createContext<TContext = any>(module: PromptModule<TContext>): TContext;
|
|
10
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EAUf,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,wBAAgB,OAAO,CAAC,QAAQ,GAAG,GAAG,EACpC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,EAC9B,OAAO,CAAC,EAAE,QAAQ,GACjB,cAAc,CA2DhB;AA4ID;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,GAAG,GAAG,EAC1C,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAC7B,QAAQ,CAKV"}
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { STANDARD_SECTIONS } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* モジュールとコンテキストからプロンプトをコンパイル
|
|
4
|
+
*/
|
|
5
|
+
export function compile(module, context) {
|
|
6
|
+
// コンテキストが提供されていない場合、module.createContextから生成
|
|
7
|
+
const actualContext = context ?? (module.createContext ? module.createContext() : {});
|
|
8
|
+
const compiled = {
|
|
9
|
+
instructions: [],
|
|
10
|
+
data: [],
|
|
11
|
+
output: []
|
|
12
|
+
};
|
|
13
|
+
// 標準セクションを処理
|
|
14
|
+
for (const sectionName of Object.keys(STANDARD_SECTIONS)) {
|
|
15
|
+
let sectionContent = module[sectionName];
|
|
16
|
+
if (!sectionContent)
|
|
17
|
+
continue;
|
|
18
|
+
const sectionDef = STANDARD_SECTIONS[sectionName];
|
|
19
|
+
// schemaセクションの場合、先にJSONElementを抽出してmetadataに設定
|
|
20
|
+
if (sectionName === 'schema') {
|
|
21
|
+
const contentArray = Array.isArray(sectionContent) ? sectionContent : [sectionContent];
|
|
22
|
+
// JSONElementを探してmetadataに抽出
|
|
23
|
+
for (const item of contentArray) {
|
|
24
|
+
if (item && typeof item === 'object' && 'type' in item && item.type === 'json') {
|
|
25
|
+
const jsonElement = item;
|
|
26
|
+
const schema = typeof jsonElement.content === 'string'
|
|
27
|
+
? JSON.parse(jsonElement.content)
|
|
28
|
+
: jsonElement.content;
|
|
29
|
+
compiled.metadata = {
|
|
30
|
+
outputSchema: schema
|
|
31
|
+
};
|
|
32
|
+
// JSONElementを除外した残りのcontentで処理を続ける
|
|
33
|
+
const filteredContent = contentArray.filter(el => !(el && typeof el === 'object' && 'type' in el && el.type === 'json'));
|
|
34
|
+
sectionContent = filteredContent.length > 0 ? filteredContent : [];
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// JSONElementを除外した後、contentが空なら何も追加しない
|
|
39
|
+
if (Array.isArray(sectionContent) && sectionContent.length === 0) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const elements = compileSectionToElements(sectionContent, sectionDef.title, sectionDef.type, sectionName, actualContext);
|
|
44
|
+
compiled[sectionDef.type].push(...elements);
|
|
45
|
+
}
|
|
46
|
+
return compiled;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* セクションコンテンツをElement配列にコンパイル
|
|
50
|
+
* DynamicElementはそのまま保持し、文字列やSubSectionはSectionElementにまとめる
|
|
51
|
+
*/
|
|
52
|
+
function compileSectionToElements(content, title, category, _sectionName, context) {
|
|
53
|
+
const elements = [];
|
|
54
|
+
const plainItems = [];
|
|
55
|
+
const subsections = [];
|
|
56
|
+
// contentを配列として扱う(文字列の場合は配列に変換)
|
|
57
|
+
const contentItems = typeof content === 'string' ? [content] : Array.isArray(content) ? content : [];
|
|
58
|
+
for (const item of contentItems) {
|
|
59
|
+
if (typeof item === 'function') {
|
|
60
|
+
// DynamicContentを実行
|
|
61
|
+
const dynamicResult = item(context);
|
|
62
|
+
const processedElements = processDynamicContentToElements(dynamicResult);
|
|
63
|
+
// DynamicElementはそのままElement配列に追加
|
|
64
|
+
for (const elem of processedElements) {
|
|
65
|
+
if (typeof elem === 'string') {
|
|
66
|
+
plainItems.push(elem);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// DynamicElementを直接追加
|
|
70
|
+
elements.push(elem);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (typeof item === 'string') {
|
|
75
|
+
// 文字列をそのまま追加
|
|
76
|
+
plainItems.push(item);
|
|
77
|
+
}
|
|
78
|
+
else if (item && typeof item === 'object' && 'type' in item) {
|
|
79
|
+
// Element型のオブジェクト
|
|
80
|
+
if (item.type === 'subsection') {
|
|
81
|
+
// サブセクション内のSimpleDynamicContentを処理
|
|
82
|
+
const processedItems = [];
|
|
83
|
+
for (const subItem of item.items) {
|
|
84
|
+
if (typeof subItem === 'function') {
|
|
85
|
+
// SimpleDynamicContentを実行
|
|
86
|
+
const result = processSimpleDynamicContent(subItem, context);
|
|
87
|
+
processedItems.push(...result);
|
|
88
|
+
}
|
|
89
|
+
else if (typeof subItem === 'string') {
|
|
90
|
+
processedItems.push(subItem);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// 処理済みのサブセクションを追加
|
|
94
|
+
subsections.push({
|
|
95
|
+
...item,
|
|
96
|
+
items: processedItems
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// その他のElement(text, message, material, chunk, json, section)を直接追加
|
|
101
|
+
elements.push(item);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// 何らかの内容がある場合は、SectionElementを作成
|
|
106
|
+
// (標準セクションは空でなければSectionElementとして表現される)
|
|
107
|
+
// elements配列に内容がある場合も考慮(MessageElement、MaterialElement等)
|
|
108
|
+
const hasContent = elements.length > 0 || plainItems.length > 0 || subsections.length > 0;
|
|
109
|
+
if (hasContent) {
|
|
110
|
+
const sectionElement = {
|
|
111
|
+
type: 'section',
|
|
112
|
+
category,
|
|
113
|
+
title,
|
|
114
|
+
items: [...plainItems, ...subsections]
|
|
115
|
+
};
|
|
116
|
+
elements.unshift(sectionElement); // セクションを先頭に追加
|
|
117
|
+
}
|
|
118
|
+
return elements;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* DynamicContentの結果をElement配列または文字列配列に変換
|
|
122
|
+
* DynamicElementはそのまま保持
|
|
123
|
+
*/
|
|
124
|
+
function processDynamicContentToElements(result) {
|
|
125
|
+
// null/undefinedの場合は空配列
|
|
126
|
+
if (result === null || result === undefined) {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
// 文字列の場合
|
|
130
|
+
if (typeof result === 'string') {
|
|
131
|
+
return [result];
|
|
132
|
+
}
|
|
133
|
+
// 配列の場合
|
|
134
|
+
if (Array.isArray(result)) {
|
|
135
|
+
return result.flatMap(item => {
|
|
136
|
+
if (typeof item === 'string') {
|
|
137
|
+
return item; // 文字列はそのまま
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return item; // DynamicElementはそのまま保持
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// 単一のElementの場合
|
|
145
|
+
return [result];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* SimpleDynamicContentの結果を文字列配列に変換
|
|
149
|
+
*/
|
|
150
|
+
function processSimpleDynamicContent(fn, context) {
|
|
151
|
+
const result = fn(context);
|
|
152
|
+
if (result === null || result === undefined) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
if (typeof result === 'string') {
|
|
156
|
+
return [result];
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(result)) {
|
|
159
|
+
// string[]のみを受け入れる
|
|
160
|
+
return result.filter((item) => typeof item === 'string');
|
|
161
|
+
}
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* コンテキストを作成するヘルパー関数
|
|
166
|
+
*/
|
|
167
|
+
export function createContext(module) {
|
|
168
|
+
if (module.createContext) {
|
|
169
|
+
return module.createContext();
|
|
170
|
+
}
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,OAAO,CACrB,MAA8B,EAC9B,OAAkB;IAElB,6CAA6C;IAC7C,MAAM,aAAa,GAAG,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,C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,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC5C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,mBAAmB;QACnB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAGD;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA8B;IAE9B,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,EAAc,CAAC;AACxB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @modular-prompt/core
|
|
3
|
+
* Core functionality for the Modular Prompt Framework
|
|
4
|
+
*/
|
|
5
|
+
// Export all types
|
|
6
|
+
export * from './types.js';
|
|
7
|
+
// Export merge functionality
|
|
8
|
+
export { merge } from './merge.js';
|
|
9
|
+
// Export compile functionality
|
|
10
|
+
export { compile, createContext } from './compile.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mBAAmB;AACnB,cAAc,YAAY,CAAC;AAE3B,6BAA6B;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,+BAA+B;AAC/B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/merge.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PromptModule } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 複数のPromptModuleをマージ
|
|
4
|
+
*/
|
|
5
|
+
export declare function merge<T1, T2>(module1: PromptModule<T1>, module2: PromptModule<T2>): PromptModule<T1 & T2>;
|
|
6
|
+
export declare function merge<T1, T2, T3>(...modules: [PromptModule<T1>, PromptModule<T2>, PromptModule<T3>]): PromptModule<T1 & T2 & T3>;
|
|
7
|
+
export declare function merge<T1, T2, T3, T4>(...modules: [PromptModule<T1>, PromptModule<T2>, PromptModule<T3>, PromptModule<T4>]): PromptModule<T1 & T2 & T3 & T4>;
|
|
8
|
+
export declare function merge<T1, T2, T3, T4, T5>(...modules: [PromptModule<T1>, PromptModule<T2>, PromptModule<T3>, PromptModule<T4>, PromptModule<T5>]): PromptModule<T1 & T2 & T3 & T4 & T5>;
|
|
9
|
+
export declare function merge<T1, T2, T3, T4, T5, T6>(...modules: [PromptModule<T1>, PromptModule<T2>, PromptModule<T3>, PromptModule<T4>, PromptModule<T5>, PromptModule<T6>]): PromptModule<T1 & T2 & T3 & T4 & T5 & T6>;
|
|
10
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAMb,MAAM,YAAY,CAAC;AA6CpB;;GAEG;AAEH,wBAAgB,KAAK,CAAC,EAAE,EAAE,E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YAAY,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC,GACvH,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC"}
|
package/dist/merge.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { STANDARD_SECTIONS } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 2つのPromptModuleをマージ
|
|
4
|
+
*/
|
|
5
|
+
function mergeTwo(module1, module2) {
|
|
6
|
+
const result = {};
|
|
7
|
+
// createContextをマージ(両方を実行して結果を統合)
|
|
8
|
+
const creators = [module1.createContext, module2.createContext].filter(c => c !== undefined);
|
|
9
|
+
if (creators.length > 0) {
|
|
10
|
+
result.createContext = () => {
|
|
11
|
+
let mergedContext = {};
|
|
12
|
+
for (const creator of creators) {
|
|
13
|
+
const context = creator();
|
|
14
|
+
mergedContext = { ...mergedContext, ...context };
|
|
15
|
+
}
|
|
16
|
+
return mergedContext;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// 各標準セクションをマージ
|
|
20
|
+
const sectionNames = Object.keys(STANDARD_SECTIONS);
|
|
21
|
+
for (const sectionName of sectionNames) {
|
|
22
|
+
const sections = [module1[sectionName], module2[sectionName]].filter(s => s !== undefined);
|
|
23
|
+
if (sections.length > 0) {
|
|
24
|
+
// 型の不一致を解決: 異なるContext型を統合
|
|
25
|
+
result[sectionName] = mergeSectionContents(...sections);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// schemaセクションは標準セクションとして自動的にマージされる
|
|
29
|
+
// Note: schemaは他の標準セクションと同様にmergeSectionContentsでマージされます
|
|
30
|
+
// JSONElement内のスキーマオブジェクトの深いマージは行いません(浅いマージで十分)
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
// 実装(2つ以上、デフォルト)
|
|
34
|
+
export function merge(...modules) {
|
|
35
|
+
// 2つずつマージを繰り返す
|
|
36
|
+
let result = mergeTwo(modules[0], modules[1]);
|
|
37
|
+
for (let i = 2; i < modules.length; i++) {
|
|
38
|
+
result = mergeTwo(result, modules[i]);
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 複数のセクションコンテンツをマージ
|
|
44
|
+
*/
|
|
45
|
+
function mergeSectionContents(...contents) {
|
|
46
|
+
const merged = [];
|
|
47
|
+
const subsections = new Map();
|
|
48
|
+
const plainItems = [];
|
|
49
|
+
// 全てのコンテンツを分類
|
|
50
|
+
for (const content of contents) {
|
|
51
|
+
// contentが関数の場合はそのまま保持(実行はコンパイル時)
|
|
52
|
+
if (typeof content === 'function') {
|
|
53
|
+
plainItems.push(content);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
// 配列でない場合は配列に変換
|
|
57
|
+
const items = Array.isArray(content) ? content : [content];
|
|
58
|
+
for (const item of items) {
|
|
59
|
+
if (typeof item === 'function') {
|
|
60
|
+
// DynamicContentはそのまま保持
|
|
61
|
+
plainItems.push(item);
|
|
62
|
+
}
|
|
63
|
+
else if (typeof item === 'string') {
|
|
64
|
+
// 文字列はそのまま保持
|
|
65
|
+
plainItems.push(item);
|
|
66
|
+
}
|
|
67
|
+
else if (item && typeof item === 'object' && 'type' in item) {
|
|
68
|
+
// Element型のオブジェクト
|
|
69
|
+
if (item.type === 'subsection') {
|
|
70
|
+
// 同名のサブセクションをマージ
|
|
71
|
+
const existing = subsections.get(item.title);
|
|
72
|
+
if (existing) {
|
|
73
|
+
subsections.set(item.title, {
|
|
74
|
+
...item,
|
|
75
|
+
items: [...existing.items, ...item.items]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
subsections.set(item.title, item);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// その他のElement(JSONElement、MaterialElement等)はそのまま保持
|
|
84
|
+
plainItems.push(item);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// 結合順序: 通常要素 → サブセクション
|
|
90
|
+
merged.push(...plainItems);
|
|
91
|
+
merged.push(...Array.from(subsections.values()));
|
|
92
|
+
return merged;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;GAEG;AACH,SAAS,QAAQ,CACf,OAAyB,EACzB,OAAyB;IAEzB,MAAM,MAAM,GAA0B,EAAE,CAAC;IAEzC,kCAAkC;IAClC,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAE7F,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,aAAa,GAAG,GAAG,EAAE;YAC1B,IAAI,aAAa,GAAG,EAAa,CAAC;YAClC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,MAAM,OAAO,GAAG,OAAQ,EAAE,CAAC;gBAC3B,aAAa,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,EAAa,CAAC;YAC9D,CAAC;YACD,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC;IACJ,CAAC;IAED,eAAe;IACf,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAA0B,CAAC;IAE7E,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAA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package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export interface Attachment {
|
|
2
|
+
type: 'text' | 'image_url' | 'file';
|
|
3
|
+
text?: string;
|
|
4
|
+
image_url?: {
|
|
5
|
+
url: string;
|
|
6
|
+
};
|
|
7
|
+
file?: {
|
|
8
|
+
path: string;
|
|
9
|
+
mime_type: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface TextElement {
|
|
13
|
+
type: 'text';
|
|
14
|
+
content: string;
|
|
15
|
+
}
|
|
16
|
+
export interface MessageElement {
|
|
17
|
+
type: 'message';
|
|
18
|
+
content: string | Attachment[];
|
|
19
|
+
role: 'system' | 'assistant' | 'user';
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface MaterialElement {
|
|
23
|
+
type: 'material';
|
|
24
|
+
content: string | Attachment[];
|
|
25
|
+
id: string;
|
|
26
|
+
title: string;
|
|
27
|
+
usage?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface ChunkElement {
|
|
30
|
+
type: 'chunk';
|
|
31
|
+
content: string | Attachment[];
|
|
32
|
+
partOf: string;
|
|
33
|
+
index?: number;
|
|
34
|
+
total?: number;
|
|
35
|
+
usage?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface SectionElement<TContext = any> {
|
|
38
|
+
type: 'section';
|
|
39
|
+
category: SectionType;
|
|
40
|
+
title: string;
|
|
41
|
+
items: (string | SubSectionElement<TContext> | DynamicContent<TContext>)[];
|
|
42
|
+
}
|
|
43
|
+
export interface SubSectionElement<TContext = any> {
|
|
44
|
+
type: 'subsection';
|
|
45
|
+
title: string;
|
|
46
|
+
items: (string | SimpleDynamicContent<TContext>)[];
|
|
47
|
+
}
|
|
48
|
+
export interface JSONElement {
|
|
49
|
+
type: 'json';
|
|
50
|
+
content: object | string;
|
|
51
|
+
}
|
|
52
|
+
export type Element<TContext = any> = TextElement | MessageElement | MaterialElement | ChunkElement | SectionElement<TContext> | SubSectionElement<TContext> | JSONElement;
|
|
53
|
+
export type DynamicElement = TextElement | MessageElement | MaterialElement | ChunkElement | JSONElement;
|
|
54
|
+
export type SimpleDynamicContent<TContext = any> = (context: TContext) => string | string[] | null | undefined;
|
|
55
|
+
export type DynamicContent<TContext = any> = (context: TContext) => string | string[] | DynamicElement | DynamicElement[] | null | undefined;
|
|
56
|
+
export type SectionContent<TContext = any> = (string | Element | DynamicContent<TContext>)[];
|
|
57
|
+
export interface PromptModule<TContext = any> {
|
|
58
|
+
createContext?: () => TContext;
|
|
59
|
+
objective?: SectionContent<TContext>;
|
|
60
|
+
terms?: SectionContent<TContext>;
|
|
61
|
+
methodology?: SectionContent<TContext>;
|
|
62
|
+
instructions?: SectionContent<TContext>;
|
|
63
|
+
guidelines?: SectionContent<TContext>;
|
|
64
|
+
preparationNote?: SectionContent<TContext>;
|
|
65
|
+
state?: SectionContent<TContext>;
|
|
66
|
+
inputs?: SectionContent<TContext>;
|
|
67
|
+
materials?: SectionContent<TContext>;
|
|
68
|
+
chunks?: SectionContent<TContext>;
|
|
69
|
+
messages?: SectionContent<TContext>;
|
|
70
|
+
cue?: SectionContent<TContext>;
|
|
71
|
+
schema?: SectionContent<TContext>;
|
|
72
|
+
sections?: SectionElement<TContext>[];
|
|
73
|
+
}
|
|
74
|
+
export declare const STANDARD_SECTIONS: {
|
|
75
|
+
readonly objective: {
|
|
76
|
+
readonly type: "instructions";
|
|
77
|
+
readonly title: "Objective and Role";
|
|
78
|
+
};
|
|
79
|
+
readonly terms: {
|
|
80
|
+
readonly type: "instructions";
|
|
81
|
+
readonly title: "Term Explanations";
|
|
82
|
+
};
|
|
83
|
+
readonly methodology: {
|
|
84
|
+
readonly type: "instructions";
|
|
85
|
+
readonly title: "Processing Methodology";
|
|
86
|
+
};
|
|
87
|
+
readonly instructions: {
|
|
88
|
+
readonly type: "instructions";
|
|
89
|
+
readonly title: "Instructions";
|
|
90
|
+
};
|
|
91
|
+
readonly guidelines: {
|
|
92
|
+
readonly type: "instructions";
|
|
93
|
+
readonly title: "Guidelines";
|
|
94
|
+
};
|
|
95
|
+
readonly preparationNote: {
|
|
96
|
+
readonly type: "instructions";
|
|
97
|
+
readonly title: "Response Preparation Note";
|
|
98
|
+
};
|
|
99
|
+
readonly state: {
|
|
100
|
+
readonly type: "data";
|
|
101
|
+
readonly title: "Current State";
|
|
102
|
+
};
|
|
103
|
+
readonly inputs: {
|
|
104
|
+
readonly type: "data";
|
|
105
|
+
readonly title: "Input Data";
|
|
106
|
+
};
|
|
107
|
+
readonly materials: {
|
|
108
|
+
readonly type: "data";
|
|
109
|
+
readonly title: "Prepared Materials";
|
|
110
|
+
};
|
|
111
|
+
readonly chunks: {
|
|
112
|
+
readonly type: "data";
|
|
113
|
+
readonly title: "Input Chunks";
|
|
114
|
+
};
|
|
115
|
+
readonly messages: {
|
|
116
|
+
readonly type: "data";
|
|
117
|
+
readonly title: "Messages";
|
|
118
|
+
};
|
|
119
|
+
readonly cue: {
|
|
120
|
+
readonly type: "output";
|
|
121
|
+
readonly title: "Output";
|
|
122
|
+
};
|
|
123
|
+
readonly schema: {
|
|
124
|
+
readonly type: "output";
|
|
125
|
+
readonly title: "Output Schema";
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
export type StandardSectionName = keyof typeof STANDARD_SECTIONS;
|
|
129
|
+
export type SectionType = 'instructions' | 'data' | 'output';
|
|
130
|
+
export interface CompiledPrompt {
|
|
131
|
+
instructions: Element[];
|
|
132
|
+
data: Element[];
|
|
133
|
+
output: Element[];
|
|
134
|
+
metadata?: {
|
|
135
|
+
outputSchema?: object;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IACpC,I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objective: { type: 'instructions', title: 'Objective and Role' },
|
|
6
|
+
terms: { type: 'instructions', title: 'Term Explanations' },
|
|
7
|
+
methodology: { type: 'instructions', title: 'Processing Methodology' },
|
|
8
|
+
instructions: { type: 'instructions', title: 'Instructions' },
|
|
9
|
+
guidelines: { type: 'instructions', title: 'Guidelines' },
|
|
10
|
+
preparationNote: { type: 'instructions', title: 'Response Preparation Note' },
|
|
11
|
+
// Data
|
|
12
|
+
state: { type: 'data', title: 'Current State' },
|
|
13
|
+
inputs: { type: 'data', title: 'Input Data' },
|
|
14
|
+
materials: { type: 'data', title: 'Prepared Materials' },
|
|
15
|
+
chunks: { type: 'data', title: 'Input Chunks' },
|
|
16
|
+
messages: { type: 'data', title: 'Messages' },
|
|
17
|
+
// Output
|
|
18
|
+
cue: { type: 'output', title: 'Output' },
|
|
19
|
+
schema: { type: 'output', title: 'Output Schema' }
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,QAAQ;AAwIR,YAAY;AACZ,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,eAAe;IACf,SAAS,EAAE,EAAE,IAAI,EAAE,cAAuB,EAAE,KAAK,EAAE,oBAAoB,EAAE;IACzE,KAAK,EAAE,EAAE,IAAI,EAAE,cAAuB,EAAE,KAAK,EAAE,mBAAmB,EAAE;IACpE,WAAW,EAAE,EAAE,IAAI,EAAE,cAAuB,EAAE,KAAK,EAAE,wBAAwB,EAAE;IAC/E,YAAY,EAAE,EAAE,IAAI,EAAE,cAAuB,EAAE,KAAK,EAAE,cAAc,EAAE;IACtE,UAAU,EAAE,EAAE,IAAI,EAAE,cAAuB,EAAE,KAAK,EAAE,YAAY,EAAE;IAClE,eAAe,EAAE,EAAE,IAAI,EAAE,cAAuB,EAAE,KAAK,EAAE,2BAA2B,EAAE;IAEtF,OAAO;IACP,KAAK,EAAE,EAAE,IAAI,EAAE,MAAe,EAAE,KAAK,EAAE,eAAe,EAAE;IACxD,MAAM,EAAE,EAAE,IAAI,EAAE,MAAe,EAAE,KAAK,EAAE,YAAY,EAAE;IACtD,SAAS,EAAE,EAAE,IAAI,EAAE,MAAe,EAAE,KAAK,EAAE,oBAAoB,EAAE;IACjE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAe,EAAE,KAAK,EAAE,cAAc,EAAE;IACxD,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAe,EAAE,KAAK,EAAE,UAAU,EAAE;IAEtD,SAAS;IACT,GAAG,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE,KAAK,EAAE,QAAQ,EAAE;IACjD,MAAM,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE,KAAK,EAAE,eAAe,EAAE;CACnD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@modular-prompt/core",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "Core module for modular prompt framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./prompts": {
|
|
14
|
+
"types": "./dist/prompts/index.d.ts",
|
|
15
|
+
"import": "./dist/prompts/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"GUIDE.md"
|
|
21
|
+
],
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@eslint/js": "^9.34.0",
|
|
24
|
+
"@types/node": "^20.0.0",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^8.42.0",
|
|
26
|
+
"@typescript-eslint/parser": "^8.42.0",
|
|
27
|
+
"@vitest/ui": "^3.2.4",
|
|
28
|
+
"eslint": "^9.34.0",
|
|
29
|
+
"typescript": "^5.0.0",
|
|
30
|
+
"vitest": "^3.2.4"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.0.0"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/otolab/moduler-prompt.git",
|
|
38
|
+
"directory": "packages/core"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"prompt",
|
|
42
|
+
"module",
|
|
43
|
+
"ai",
|
|
44
|
+
"llm",
|
|
45
|
+
"core"
|
|
46
|
+
],
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"registry": "https://registry.npmjs.org/"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsc -b --force",
|
|
54
|
+
"dev": "tsc --watch",
|
|
55
|
+
"test": "vitest",
|
|
56
|
+
"test:ui": "vitest --ui",
|
|
57
|
+
"test:run": "vitest run",
|
|
58
|
+
"clean": "rm -rf dist",
|
|
59
|
+
"lint": "eslint src",
|
|
60
|
+
"typecheck": "tsc --noEmit"
|
|
61
|
+
}
|
|
62
|
+
}
|