@promptbook/cli 0.103.0-54 → 0.103.0-55
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/apps/agents-server/config.ts +0 -2
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +79 -6
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +171 -69
- package/apps/agents-server/src/app/agents/[agentName]/api/mcp/route.ts +203 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/route.ts +3 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/systemMessage/route.ts +3 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/chat/completions/route.ts +3 -169
- package/apps/agents-server/src/app/agents/[agentName]/api/openrouter/chat/completions/route.ts +10 -0
- package/apps/agents-server/src/app/agents/[agentName]/links/page.tsx +218 -0
- package/apps/agents-server/src/app/api/auth/change-password/route.ts +75 -0
- package/apps/agents-server/src/app/api/chat-feedback/export/route.ts +55 -0
- package/apps/agents-server/src/app/api/chat-history/export/route.ts +55 -0
- package/apps/agents-server/src/components/ChangePasswordDialog/ChangePasswordDialog.tsx +41 -0
- package/apps/agents-server/src/components/ChangePasswordForm/ChangePasswordForm.tsx +159 -0
- package/apps/agents-server/src/components/Header/Header.tsx +94 -38
- package/apps/agents-server/src/middleware.ts +1 -1
- package/apps/agents-server/src/utils/convertToCsv.ts +31 -0
- package/apps/agents-server/src/utils/handleChatCompletion.ts +183 -0
- package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +93 -0
- package/esm/index.es.js +770 -181
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +8 -6
- package/esm/typings/src/_packages/types.index.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +4 -0
- package/esm/typings/src/commitments/CLOSED/CLOSED.d.ts +35 -0
- package/esm/typings/src/commitments/COMPONENT/COMPONENT.d.ts +28 -0
- package/esm/typings/src/commitments/FROM/FROM.d.ts +34 -0
- package/esm/typings/src/commitments/IMPORTANT/IMPORTANT.d.ts +26 -0
- package/esm/typings/src/commitments/LANGUAGE/LANGUAGE.d.ts +35 -0
- package/esm/typings/src/commitments/OPEN/OPEN.d.ts +35 -0
- package/esm/typings/src/commitments/index.d.ts +1 -82
- package/esm/typings/src/commitments/registry.d.ts +68 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +770 -181
- package/umd/index.umd.js.map +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createAgentModelRequirements } from '@promptbook-local/core';
|
|
2
|
+
import type { AgentCollection } from '@promptbook-local/types';
|
|
3
|
+
type string_book = string & { readonly __type: 'book' };
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Resolves agent source with inheritance (FROM commitment)
|
|
7
|
+
*
|
|
8
|
+
* It recursively fetches the parent agent source and merges it with the current source.
|
|
9
|
+
*
|
|
10
|
+
* @param agentSource The initial agent source
|
|
11
|
+
* @param collection Optional agent collection to resolve local agents efficiently
|
|
12
|
+
* @returns The resolved agent source with inheritance applied
|
|
13
|
+
*/
|
|
14
|
+
export async function resolveInheritedAgentSource(
|
|
15
|
+
agentSource: string_book,
|
|
16
|
+
collection?: AgentCollection,
|
|
17
|
+
): Promise<string_book> {
|
|
18
|
+
// Check if the source has FROM commitment
|
|
19
|
+
// We use createAgentModelRequirements to parse commitments
|
|
20
|
+
// Note: We don't provide tools/models here as we only care about parsing commitments
|
|
21
|
+
const requirements = await createAgentModelRequirements(agentSource);
|
|
22
|
+
|
|
23
|
+
if (!requirements.parentAgentUrl) {
|
|
24
|
+
return agentSource;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const parentUrl = requirements.parentAgentUrl;
|
|
28
|
+
let parentSource: string_book;
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
// 1. Try to resolve locally using collection if possible
|
|
32
|
+
// This is an optimization for internal agents
|
|
33
|
+
// We assume the URL might be relative or contain the agent name, or we just check if it's a full URL
|
|
34
|
+
// If it's a full URL, we need to check if it matches our server, but without knowing our server URL it's hard.
|
|
35
|
+
// So we might need to parse the URL to extract agent name if it matches expected pattern.
|
|
36
|
+
// For now, let's rely on fetch for external and check collection if it looks like a local reference (though FROM expects URL)
|
|
37
|
+
|
|
38
|
+
// If the URL is valid, we try to fetch it
|
|
39
|
+
// TODO: Handle authentication/tokens for private agents if needed
|
|
40
|
+
const response = await fetch(parentUrl);
|
|
41
|
+
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`Failed to fetch parent agent from ${parentUrl}: ${response.status} ${response.statusText}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// We assume the response is the agent source text
|
|
47
|
+
// TODO: Handle content negotiation or JSON responses if the server returns JSON
|
|
48
|
+
const contentType = response.headers.get('content-type');
|
|
49
|
+
if (contentType && contentType.includes('application/json')) {
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
// Assume some structure or that the API returns source in a property
|
|
52
|
+
// For Agents Server API modelRequirements/route.ts returns AgentModelRequirements, not source.
|
|
53
|
+
// If we point to a raw source endpoint, it returns text.
|
|
54
|
+
// If we point to the agent page, it returns HTML.
|
|
55
|
+
// We need a standard way to get source.
|
|
56
|
+
// For now, let's assume the URL points to the source or an API returning source.
|
|
57
|
+
if (typeof data === 'string') {
|
|
58
|
+
parentSource = data as string_book;
|
|
59
|
+
} else if (data.source) {
|
|
60
|
+
parentSource = data.source as string_book;
|
|
61
|
+
} else {
|
|
62
|
+
// Fallback or error
|
|
63
|
+
console.warn(`Received JSON from ${parentUrl} but couldn't determine source property. Using text.`);
|
|
64
|
+
// Re-fetch as text? Or assume body text was read? response.json() consumes body.
|
|
65
|
+
// So we might have failed here.
|
|
66
|
+
throw new Error(`Received JSON from ${parentUrl} but structure is unknown.`);
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
parentSource = (await response.text()) as string_book;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.warn(`Failed to resolve parent agent ${parentUrl}`, error);
|
|
74
|
+
// If we fail to resolve parent, we return the original source (maybe with a warning or error commitment?)
|
|
75
|
+
// Or we could throw to fail the build.
|
|
76
|
+
// For robustness, let's append a warning comment
|
|
77
|
+
return `${agentSource}\n\n# Warning: Failed to inherit from ${parentUrl}: ${error}` as string_book;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Recursively resolve the parent source
|
|
81
|
+
const effectiveParentSource = await resolveInheritedAgentSource(parentSource, collection);
|
|
82
|
+
|
|
83
|
+
// Strip the FROM commitment from the child source to avoid infinite recursion or re-processing
|
|
84
|
+
// We can filter lines starting with FROM
|
|
85
|
+
const childSourceLines = agentSource.split('\n');
|
|
86
|
+
const filteredChildSource = childSourceLines
|
|
87
|
+
.filter((line: string) => !line.trim().startsWith('FROM ')) // Simple string check, ideally should use parser location
|
|
88
|
+
.join('\n');
|
|
89
|
+
|
|
90
|
+
// Append child source to parent source
|
|
91
|
+
// "appends the RULE commitment to its source" -> Parent + Child
|
|
92
|
+
return `${effectiveParentSource}\n\n${filteredChildSource}` as string_book;
|
|
93
|
+
}
|