Refactor Assistant script handling to use HookScript
- Replaced all instances of `Script` with `HookScript` in the Assistant and related files to improve clarity and consistency in naming. - Updated method calls in the Stream, Create, and Next hooks to utilize the new `HookScript` field. - Adjusted tests and benchmarks to reflect the changes in script handling, ensuring all functionalities remain intact and operational. - Enhanced the load and initialization processes to accommodate the new HookScript structure, streamlining the assistant's script management.
This commit is contained in:
parent
a50f43a8bb
commit
0bc0821646
17 changed files with 134 additions and 134 deletions
|
|
@ -84,9 +84,9 @@ func (ast *Assistant) Stream(ctx *context.Context, inputMessages []context.Messa
|
||||||
// ================================================
|
// ================================================
|
||||||
// Request Create hook ( Optional )
|
// Request Create hook ( Optional )
|
||||||
var createResponse *context.HookCreateResponse
|
var createResponse *context.HookCreateResponse
|
||||||
if ast.Script != nil {
|
if ast.HookScript != nil {
|
||||||
var err error
|
var err error
|
||||||
createResponse, opts, err = ast.Script.Create(ctx, fullMessages, opts)
|
createResponse, opts, err = ast.HookScript.Create(ctx, fullMessages, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ast.traceAgentFail(agentNode, err)
|
ast.traceAgentFail(agentNode, err)
|
||||||
// Send error stream_end for root stack
|
// Send error stream_end for root stack
|
||||||
|
|
@ -234,9 +234,9 @@ func (ast *Assistant) Stream(ctx *context.Context, inputMessages []context.Messa
|
||||||
var finalResponse interface{}
|
var finalResponse interface{}
|
||||||
var nextResponse *context.NextHookResponse = nil
|
var nextResponse *context.NextHookResponse = nil
|
||||||
|
|
||||||
if ast.Script != nil {
|
if ast.HookScript != nil {
|
||||||
var err error
|
var err error
|
||||||
nextResponse, opts, err = ast.Script.Next(ctx, &context.NextHookPayload{
|
nextResponse, opts, err = ast.HookScript.Next(ctx, &context.NextHookPayload{
|
||||||
Messages: fullMessages,
|
Messages: fullMessages,
|
||||||
Completion: completionResponse,
|
Completion: completionResponse,
|
||||||
Tools: toolCallResponses,
|
Tools: toolCallResponses,
|
||||||
|
|
|
||||||
|
|
@ -183,9 +183,9 @@ func (ast *Assistant) Clone() *Assistant {
|
||||||
CreatedAt: ast.CreatedAt,
|
CreatedAt: ast.CreatedAt,
|
||||||
UpdatedAt: ast.UpdatedAt,
|
UpdatedAt: ast.UpdatedAt,
|
||||||
},
|
},
|
||||||
Search: ast.Search,
|
Search: ast.Search,
|
||||||
Script: ast.Script,
|
HookScript: ast.HookScript,
|
||||||
openai: ast.openai,
|
openai: ast.openai,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deep copy tags
|
// Deep copy tags
|
||||||
|
|
|
||||||
|
|
@ -214,8 +214,8 @@ func TestBuildRequest_MCP(t *testing.T) {
|
||||||
|
|
||||||
// Call create hook to get createResponse
|
// Call create hook to get createResponse
|
||||||
var createResponse *context.HookCreateResponse
|
var createResponse *context.HookCreateResponse
|
||||||
if hookAgent.Script != nil {
|
if hookAgent.HookScript != nil {
|
||||||
createResponse, _, err = hookAgent.Script.Create(hookCtx, inputMessages, &context.Options{})
|
createResponse, _, err = hookAgent.HookScript.Create(hookCtx, inputMessages, &context.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to call create hook: %s", err.Error())
|
t.Fatalf("Failed to call create hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -636,7 +636,7 @@ func TestPromptPresetAssistant(t *testing.T) {
|
||||||
assert.Contains(t, ast.PromptPresets, "mode.professional")
|
assert.Contains(t, ast.PromptPresets, "mode.professional")
|
||||||
|
|
||||||
// Should have script
|
// Should have script
|
||||||
assert.NotNil(t, ast.Script)
|
assert.NotNil(t, ast.HookScript)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("CreateHookSelectsFriendlyPreset", func(t *testing.T) {
|
t.Run("CreateHookSelectsFriendlyPreset", func(t *testing.T) {
|
||||||
|
|
@ -650,7 +650,7 @@ func TestPromptPresetAssistant(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call Create hook
|
// Call Create hook
|
||||||
createResponse, _, err := ast.Script.Create(ctx, messages, &context.Options{})
|
createResponse, _, err := ast.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, createResponse)
|
require.NotNil(t, createResponse)
|
||||||
assert.Equal(t, "mode.friendly", createResponse.PromptPreset)
|
assert.Equal(t, "mode.friendly", createResponse.PromptPreset)
|
||||||
|
|
@ -681,7 +681,7 @@ func TestPromptPresetAssistant(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call Create hook
|
// Call Create hook
|
||||||
createResponse, _, err := ast.Script.Create(ctx, messages, &context.Options{})
|
createResponse, _, err := ast.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, createResponse)
|
require.NotNil(t, createResponse)
|
||||||
assert.Equal(t, "mode.professional", createResponse.PromptPreset)
|
assert.Equal(t, "mode.professional", createResponse.PromptPreset)
|
||||||
|
|
@ -718,7 +718,7 @@ func TestPromptPresetAssistant(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call Create hook
|
// Call Create hook
|
||||||
createResponse, _, err := ast.Script.Create(ctx, messages, &context.Options{})
|
createResponse, _, err := ast.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, createResponse)
|
require.NotNil(t, createResponse)
|
||||||
require.NotNil(t, createResponse.DisableGlobalPrompts)
|
require.NotNil(t, createResponse.DisableGlobalPrompts)
|
||||||
|
|
@ -753,7 +753,7 @@ func TestPromptPresetAssistant(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call Create hook
|
// Call Create hook
|
||||||
createResponse, _, err := ast.Script.Create(ctx, messages, &context.Options{})
|
createResponse, _, err := ast.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, createResponse)
|
require.NotNil(t, createResponse)
|
||||||
assert.Equal(t, "mode.friendly", createResponse.PromptPreset)
|
assert.Equal(t, "mode.friendly", createResponse.PromptPreset)
|
||||||
|
|
@ -788,7 +788,7 @@ func TestPromptPresetAssistant(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call Create hook
|
// Call Create hook
|
||||||
createResponse, _, err := ast.Script.Create(ctx, messages, &context.Options{})
|
createResponse, _, err := ast.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, createResponse)
|
require.NotNil(t, createResponse)
|
||||||
assert.Equal(t, "non.existent.preset", createResponse.PromptPreset)
|
assert.Equal(t, "non.existent.preset", createResponse.PromptPreset)
|
||||||
|
|
@ -819,7 +819,7 @@ func TestPromptPresetAssistant(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call Create hook - should return nil
|
// Call Create hook - should return nil
|
||||||
createResponse, _, err := ast.Script.Create(ctx, messages, &context.Options{})
|
createResponse, _, err := ast.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Nil(t, createResponse)
|
assert.Nil(t, createResponse)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ func TestBuildRequest(t *testing.T) {
|
||||||
t.Fatalf("Failed to get tests.buildrequest assistant: %s", err.Error())
|
t.Fatalf("Failed to get tests.buildrequest assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("The tests.buildrequest assistant has no script")
|
t.Fatalf("The tests.buildrequest assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ func TestBuildRequest(t *testing.T) {
|
||||||
inputMessages := []context.Message{{Role: "user", Content: "no_override"}}
|
inputMessages := []context.Message{{Role: "user", Content: "no_override"}}
|
||||||
|
|
||||||
// Call Create hook
|
// Call Create hook
|
||||||
createResponse, _, err := agent.Script.Create(ctx, inputMessages, &context.Options{})
|
createResponse, _, err := agent.HookScript.Create(ctx, inputMessages, &context.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to call Create hook: %s", err.Error())
|
t.Fatalf("Failed to call Create hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ func TestBuildRequest(t *testing.T) {
|
||||||
t.Run("OverrideTemperature", func(t *testing.T) {
|
t.Run("OverrideTemperature", func(t *testing.T) {
|
||||||
inputMessages := []context.Message{{Role: "user", Content: "override_temperature"}}
|
inputMessages := []context.Message{{Role: "user", Content: "override_temperature"}}
|
||||||
|
|
||||||
createResponse, _, err := agent.Script.Create(ctx, inputMessages, &context.Options{})
|
createResponse, _, err := agent.HookScript.Create(ctx, inputMessages, &context.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to call Create hook: %s", err.Error())
|
t.Fatalf("Failed to call Create hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +142,7 @@ func TestBuildRequest(t *testing.T) {
|
||||||
t.Run("OverrideAll", func(t *testing.T) {
|
t.Run("OverrideAll", func(t *testing.T) {
|
||||||
inputMessages := []context.Message{{Role: "user", Content: "override_all"}}
|
inputMessages := []context.Message{{Role: "user", Content: "override_all"}}
|
||||||
|
|
||||||
createResponse, _, err := agent.Script.Create(ctx, inputMessages, &context.Options{})
|
createResponse, _, err := agent.HookScript.Create(ctx, inputMessages, &context.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to call Create hook: %s", err.Error())
|
t.Fatalf("Failed to call Create hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +195,7 @@ func TestBuildRequest(t *testing.T) {
|
||||||
t.Run("OverrideRouteMetadata", func(t *testing.T) {
|
t.Run("OverrideRouteMetadata", func(t *testing.T) {
|
||||||
inputMessages := []context.Message{{Role: "user", Content: "override_route_metadata"}}
|
inputMessages := []context.Message{{Role: "user", Content: "override_route_metadata"}}
|
||||||
|
|
||||||
createResponse, _, err := agent.Script.Create(ctx, inputMessages, &context.Options{})
|
createResponse, _, err := agent.HookScript.Create(ctx, inputMessages, &context.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to call Create hook: %s", err.Error())
|
t.Fatalf("Failed to call Create hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,14 @@ func BenchmarkSimpleStandardMode(b *testing.B) {
|
||||||
b.Fatalf("Failed to get assistant: %s", err.Error())
|
b.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
b.Fatalf("Assistant has no script")
|
b.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ctx := newBenchContext("bench-simple-standard", "tests.create")
|
ctx := newBenchContext("bench-simple-standard", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -54,14 +54,14 @@ func BenchmarkSimplePerformanceMode(b *testing.B) {
|
||||||
b.Fatalf("Failed to get assistant: %s", err.Error())
|
b.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
b.Fatalf("Assistant has no script")
|
b.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ctx := newBenchContext("bench-simple-performance", "tests.create")
|
ctx := newBenchContext("bench-simple-performance", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -85,7 +85,7 @@ func BenchmarkBusinessStandardMode(b *testing.B) {
|
||||||
b.Fatalf("Failed to get assistant: %s", err.Error())
|
b.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
b.Fatalf("Assistant has no script")
|
b.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ func BenchmarkBusinessStandardMode(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
scenario := scenarios[i%len(scenarios)]
|
scenario := scenarios[i%len(scenarios)]
|
||||||
ctx := newBenchContext("bench-business-standard", "tests.create")
|
ctx := newBenchContext("bench-business-standard", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: scenario.content},
|
{Role: "user", Content: scenario.content},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -115,7 +115,7 @@ func BenchmarkBusinessPerformanceMode(b *testing.B) {
|
||||||
b.Fatalf("Failed to get assistant: %s", err.Error())
|
b.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
b.Fatalf("Assistant has no script")
|
b.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,7 +125,7 @@ func BenchmarkBusinessPerformanceMode(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
scenario := scenarios[i%len(scenarios)]
|
scenario := scenarios[i%len(scenarios)]
|
||||||
ctx := newBenchContext("bench-business-performance", "tests.create")
|
ctx := newBenchContext("bench-business-performance", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: scenario.content},
|
{Role: "user", Content: scenario.content},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -150,7 +150,7 @@ func BenchmarkConcurrentSimpleStandardMode(b *testing.B) {
|
||||||
b.Fatalf("Failed to get assistant: %s", err.Error())
|
b.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
b.Fatalf("Assistant has no script")
|
b.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,7 +159,7 @@ func BenchmarkConcurrentSimpleStandardMode(b *testing.B) {
|
||||||
i := 0
|
i := 0
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
ctx := newBenchContext("bench-concurrent-simple-standard", "tests.create")
|
ctx := newBenchContext("bench-concurrent-simple-standard", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -182,7 +182,7 @@ func BenchmarkConcurrentSimplePerformanceMode(b *testing.B) {
|
||||||
b.Fatalf("Failed to get assistant: %s", err.Error())
|
b.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
b.Fatalf("Assistant has no script")
|
b.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,7 +191,7 @@ func BenchmarkConcurrentSimplePerformanceMode(b *testing.B) {
|
||||||
i := 0
|
i := 0
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
ctx := newBenchContext("bench-concurrent-simple", "tests.create")
|
ctx := newBenchContext("bench-concurrent-simple", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -214,7 +214,7 @@ func BenchmarkConcurrentBusinessStandardMode(b *testing.B) {
|
||||||
b.Fatalf("Failed to get assistant: %s", err.Error())
|
b.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
b.Fatalf("Assistant has no script")
|
b.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +226,7 @@ func BenchmarkConcurrentBusinessStandardMode(b *testing.B) {
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
scenario := scenarios[i%len(scenarios)]
|
scenario := scenarios[i%len(scenarios)]
|
||||||
ctx := newBenchContext("bench-concurrent-business-standard", "tests.create")
|
ctx := newBenchContext("bench-concurrent-business-standard", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: scenario.content},
|
{Role: "user", Content: scenario.content},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -249,7 +249,7 @@ func BenchmarkConcurrentBusinessPerformanceMode(b *testing.B) {
|
||||||
b.Fatalf("Failed to get assistant: %s", err.Error())
|
b.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
b.Fatalf("Assistant has no script")
|
b.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,7 +261,7 @@ func BenchmarkConcurrentBusinessPerformanceMode(b *testing.B) {
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
scenario := scenarios[i%len(scenarios)]
|
scenario := scenarios[i%len(scenarios)]
|
||||||
ctx := newBenchContext("bench-concurrent-business", "tests.create")
|
ctx := newBenchContext("bench-concurrent-business", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: scenario.content},
|
{Role: "user", Content: scenario.content},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ func TestMemoryLeakStandardMode(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warm up - execute a few times to stabilize memory
|
// Warm up - execute a few times to stabilize memory
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
ctx := newMemTestContext("warmup", "tests.create")
|
ctx := newMemTestContext("warmup", "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
|
|
@ -52,7 +52,7 @@ func TestMemoryLeakStandardMode(t *testing.T) {
|
||||||
iterations := 1000
|
iterations := 1000
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
ctx := newMemTestContext("mem-test-standard", "tests.create")
|
ctx := newMemTestContext("mem-test-standard", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -117,14 +117,14 @@ func TestMemoryLeakPerformanceMode(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warm up - execute a few times to stabilize memory and fill isolate pool
|
// Warm up - execute a few times to stabilize memory and fill isolate pool
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
ctx := newMemTestContext("warmup", "tests.create")
|
ctx := newMemTestContext("warmup", "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
|
|
@ -140,7 +140,7 @@ func TestMemoryLeakPerformanceMode(t *testing.T) {
|
||||||
iterations := 1000
|
iterations := 1000
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
ctx := newMemTestContext("mem-test-performance", "tests.create")
|
ctx := newMemTestContext("mem-test-performance", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -202,7 +202,7 @@ func TestMemoryLeakBusinessScenarios(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -221,7 +221,7 @@ func TestMemoryLeakBusinessScenarios(t *testing.T) {
|
||||||
// Warm up
|
// Warm up
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
ctx := newMemTestContext("warmup", "tests.create")
|
ctx := newMemTestContext("warmup", "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "return_full"},
|
{Role: "user", Content: "return_full"},
|
||||||
})
|
})
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
|
|
@ -240,7 +240,7 @@ func TestMemoryLeakBusinessScenarios(t *testing.T) {
|
||||||
iterations := 200
|
iterations := 200
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
ctx := newMemTestContext("mem-test-business", "tests.create")
|
ctx := newMemTestContext("mem-test-business", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: scenario.content},
|
{Role: "user", Content: scenario.content},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -291,14 +291,14 @@ func TestMemoryLeakConcurrent(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warm up
|
// Warm up
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
ctx := newMemTestContext("warmup", "tests.create")
|
ctx := newMemTestContext("warmup", "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
|
|
@ -321,7 +321,7 @@ func TestMemoryLeakConcurrent(t *testing.T) {
|
||||||
defer func() { done <- true }()
|
defer func() { done <- true }()
|
||||||
for i := 0; i < iterPerGoroutine; i++ {
|
for i := 0; i < iterPerGoroutine; i++ {
|
||||||
ctx := newMemTestContext("mem-test-concurrent", "tests.create")
|
ctx := newMemTestContext("mem-test-concurrent", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -376,14 +376,14 @@ func TestMemoryLeakNestedCalls(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warm up
|
// Warm up
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
ctx := newMemTestContext("warmup", "tests.create")
|
ctx := newMemTestContext("warmup", "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "nested_script_call"},
|
{Role: "user", Content: "nested_script_call"},
|
||||||
})
|
})
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
|
|
@ -400,7 +400,7 @@ func TestMemoryLeakNestedCalls(t *testing.T) {
|
||||||
iterations := 200
|
iterations := 200
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
ctx := newMemTestContext("mem-test-nested", "tests.create")
|
ctx := newMemTestContext("mem-test-nested", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "deep_nested_call"},
|
{Role: "user", Content: "deep_nested_call"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -452,14 +452,14 @@ func TestMemoryLeakNestedConcurrent(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warm up
|
// Warm up
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
ctx := newMemTestContext("warmup", "tests.create")
|
ctx := newMemTestContext("warmup", "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "nested_script_call"},
|
{Role: "user", Content: "nested_script_call"},
|
||||||
})
|
})
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
|
|
@ -482,7 +482,7 @@ func TestMemoryLeakNestedConcurrent(t *testing.T) {
|
||||||
defer func() { done <- true }()
|
defer func() { done <- true }()
|
||||||
for i := 0; i < iterPerGoroutine; i++ {
|
for i := 0; i < iterPerGoroutine; i++ {
|
||||||
ctx := newMemTestContext("mem-test-nested-concurrent", "tests.create")
|
ctx := newMemTestContext("mem-test-nested-concurrent", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "deep_nested_call"},
|
{Role: "user", Content: "deep_nested_call"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -538,7 +538,7 @@ func TestIsolateDisposal(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -549,7 +549,7 @@ func TestIsolateDisposal(t *testing.T) {
|
||||||
iterations := 100
|
iterations := 100
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
ctx := newMemTestContext("disposal-test", "tests.create")
|
ctx := newMemTestContext("disposal-test", "tests.create")
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func TestNestedScriptCall(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ func TestNestedScriptCall(t *testing.T) {
|
||||||
|
|
||||||
// Call with deep_nested_call scenario
|
// Call with deep_nested_call scenario
|
||||||
// This will: hook -> scripts.tests.create.NestedCall -> GetRoles -> model
|
// This will: hook -> scripts.tests.create.NestedCall -> GetRoles -> model
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "deep_nested_call"},
|
{Role: "user", Content: "deep_nested_call"},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ func TestNestedScriptCallConcurrent(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ func TestNestedScriptCallConcurrent(t *testing.T) {
|
||||||
for j := 0; j < iterations; j++ {
|
for j := 0; j < iterations; j++ {
|
||||||
ctx := newTestContext("test-concurrent", "tests.create")
|
ctx := newTestContext("test-concurrent", "tests.create")
|
||||||
|
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "deep_nested_call"},
|
{Role: "user", Content: "deep_nested_call"},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func TestCreate(t *testing.T) {
|
||||||
t.Fatalf("Failed to get the tests.create assistant: %s", err.Error())
|
t.Fatalf("Failed to get the tests.create assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("The tests.create assistant has no script")
|
t.Fatalf("The tests.create assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ func TestCreate(t *testing.T) {
|
||||||
|
|
||||||
// Test scenario 1: Return null (should get nil response)
|
// Test scenario 1: Return null (should get nil response)
|
||||||
t.Run("ReturnNull", func(t *testing.T) {
|
t.Run("ReturnNull", func(t *testing.T) {
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{{Role: "user", Content: "return_null"}})
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{{Role: "user", Content: "return_null"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with null return: %s", err.Error())
|
t.Fatalf("Failed to create with null return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +84,7 @@ func TestCreate(t *testing.T) {
|
||||||
|
|
||||||
// Test scenario 2: Return undefined (should get nil response)
|
// Test scenario 2: Return undefined (should get nil response)
|
||||||
t.Run("ReturnUndefined", func(t *testing.T) {
|
t.Run("ReturnUndefined", func(t *testing.T) {
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{{Role: "user", Content: "return_undefined"}})
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{{Role: "user", Content: "return_undefined"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with undefined return: %s", err.Error())
|
t.Fatalf("Failed to create with undefined return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +95,7 @@ func TestCreate(t *testing.T) {
|
||||||
|
|
||||||
// Test scenario 3: Return empty object (should get empty HookCreateResponse)
|
// Test scenario 3: Return empty object (should get empty HookCreateResponse)
|
||||||
t.Run("ReturnEmpty", func(t *testing.T) {
|
t.Run("ReturnEmpty", func(t *testing.T) {
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{{Role: "user", Content: "return_empty"}})
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{{Role: "user", Content: "return_empty"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with empty return: %s", err.Error())
|
t.Fatalf("Failed to create with empty return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ func TestCreate(t *testing.T) {
|
||||||
|
|
||||||
// Test scenario 4: Return full response with all fields
|
// Test scenario 4: Return full response with all fields
|
||||||
t.Run("ReturnFull", func(t *testing.T) {
|
t.Run("ReturnFull", func(t *testing.T) {
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{{Role: "user", Content: "return_full"}})
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{{Role: "user", Content: "return_full"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with full return: %s", err.Error())
|
t.Fatalf("Failed to create with full return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +165,7 @@ func TestCreate(t *testing.T) {
|
||||||
|
|
||||||
// Test scenario 5: Return partial response
|
// Test scenario 5: Return partial response
|
||||||
t.Run("ReturnPartial", func(t *testing.T) {
|
t.Run("ReturnPartial", func(t *testing.T) {
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{{Role: "user", Content: "return_partial"}})
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{{Role: "user", Content: "return_partial"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with partial return: %s", err.Error())
|
t.Fatalf("Failed to create with partial return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +196,7 @@ func TestCreate(t *testing.T) {
|
||||||
|
|
||||||
// Test scenario 6: Process call - calls models.__yao.role.Get and adds to messages
|
// Test scenario 6: Process call - calls models.__yao.role.Get and adds to messages
|
||||||
t.Run("ReturnProcess", func(t *testing.T) {
|
t.Run("ReturnProcess", func(t *testing.T) {
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{{Role: "user", Content: "return_process"}})
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{{Role: "user", Content: "return_process"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with process return: %s", err.Error())
|
t.Fatalf("Failed to create with process return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -224,7 +224,7 @@ func TestCreate(t *testing.T) {
|
||||||
// Test scenario 7: Default response
|
// Test scenario 7: Default response
|
||||||
t.Run("ReturnDefault", func(t *testing.T) {
|
t.Run("ReturnDefault", func(t *testing.T) {
|
||||||
testContent := "Hello, how are you?"
|
testContent := "Hello, how are you?"
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{{Role: "user", Content: testContent}})
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{{Role: "user", Content: testContent}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with default return: %s", err.Error())
|
t.Fatalf("Failed to create with default return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +251,7 @@ func TestCreate(t *testing.T) {
|
||||||
|
|
||||||
// Test scenario 8: Verify context fields - validates all context fields in JavaScript
|
// Test scenario 8: Verify context fields - validates all context fields in JavaScript
|
||||||
t.Run("VerifyContext", func(t *testing.T) {
|
t.Run("VerifyContext", func(t *testing.T) {
|
||||||
res, _, err := agent.Script.Create(ctx, []context.Message{{Role: "user", Content: "verify_context"}})
|
res, _, err := agent.HookScript.Create(ctx, []context.Message{{Role: "user", Content: "verify_context"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with verify_context: %s", err.Error())
|
t.Fatalf("Failed to create with verify_context: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -303,7 +303,7 @@ func TestCreate(t *testing.T) {
|
||||||
adjustCtx := newTestContext("chat-test-adjust", "tests.create")
|
adjustCtx := newTestContext("chat-test-adjust", "tests.create")
|
||||||
|
|
||||||
// Call the hook which should adjust context fields
|
// Call the hook which should adjust context fields
|
||||||
res, _, err := agent.Script.Create(adjustCtx, []context.Message{{Role: "user", Content: "adjust_context"}})
|
res, _, err := agent.HookScript.Create(adjustCtx, []context.Message{{Role: "user", Content: "adjust_context"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create with adjust_context: %s", err.Error())
|
t.Fatalf("Failed to create with adjust_context: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func TestGoroutineLeakDetailed(t *testing.T) {
|
||||||
t.Fatalf("Failed to get assistant: %s", err.Error())
|
t.Fatalf("Failed to get assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("Assistant has no script")
|
t.Fatalf("Assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ func TestGoroutineLeakDetailed(t *testing.T) {
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
ctx := newLeakTestContext(fmt.Sprintf("leak-test-%d", i), "tests.create")
|
ctx := newLeakTestContext(fmt.Sprintf("leak-test-%d", i), "tests.create")
|
||||||
|
|
||||||
_, _, err := agent.Script.Create(ctx, []context.Message{
|
_, _, err := agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -126,7 +126,7 @@ func TestGoroutineLeakByComponent(t *testing.T) {
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
ctx := newLeakTestContext(fmt.Sprintf("test-%d", i), "tests.create")
|
ctx := newLeakTestContext(fmt.Sprintf("test-%d", i), "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
|
|
@ -184,7 +184,7 @@ func TestGoroutineLeakWithoutRelease(t *testing.T) {
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
ctx := newLeakTestContext(fmt.Sprintf("no-release-%d", i), "tests.create")
|
ctx := newLeakTestContext(fmt.Sprintf("no-release-%d", i), "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
// Intentionally NOT calling ctx.Release()
|
// Intentionally NOT calling ctx.Release()
|
||||||
|
|
@ -205,7 +205,7 @@ func TestGoroutineLeakWithoutRelease(t *testing.T) {
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
ctx := newLeakTestContext(fmt.Sprintf("with-release-%d", i), "tests.create")
|
ctx := newLeakTestContext(fmt.Sprintf("with-release-%d", i), "tests.create")
|
||||||
_, _, _ = agent.Script.Create(ctx, []context.Message{
|
_, _, _ = agent.HookScript.Create(ctx, []context.Message{
|
||||||
{Role: "user", Content: "Hello"},
|
{Role: "user", Content: "Hello"},
|
||||||
})
|
})
|
||||||
ctx.Release() // WITH Release
|
ctx.Release() // WITH Release
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ func TestNext(t *testing.T) {
|
||||||
t.Fatalf("Failed to get the tests.next assistant: %s", err.Error())
|
t.Fatalf("Failed to get the tests.next assistant: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if agent.Script == nil {
|
if agent.HookScript == nil {
|
||||||
t.Fatalf("The tests.next assistant has no script")
|
t.Fatalf("The tests.next assistant has no script")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ func TestNext(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook with null return: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook with null return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +105,7 @@ func TestNext(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook with undefined return: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook with undefined return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +125,7 @@ func TestNext(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook with empty return: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook with empty return: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +151,7 @@ func TestNext(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook with custom data: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook with custom data: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +198,7 @@ func TestNext(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +244,7 @@ func TestNext(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook with delegate: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook with delegate: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -306,7 +306,7 @@ func TestNext(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -365,7 +365,7 @@ func TestNext(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -409,7 +409,7 @@ func TestNext(t *testing.T) {
|
||||||
Error: "Tool execution failed: timeout",
|
Error: "Tool execution failed: timeout",
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := agent.Script.Next(ctx, payload)
|
res, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to execute Next hook: %s", err.Error())
|
t.Fatalf("Failed to execute Next hook: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ func TestRealWorldNextStandard(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Next(ctx, payload)
|
response, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Next hook failed: %v", err)
|
t.Fatalf("Next hook failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +117,7 @@ func TestRealWorldNextCustomData(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Next(ctx, payload)
|
response, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Next hook failed: %v", err)
|
t.Fatalf("Next hook failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +164,7 @@ func TestRealWorldNextDelegate(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Next(ctx, payload)
|
response, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Next hook failed: %v", err)
|
t.Fatalf("Next hook failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -226,7 +226,7 @@ func TestRealWorldNextProcessTools(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Next(ctx, payload)
|
response, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Next hook failed: %v", err)
|
t.Fatalf("Next hook failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -279,7 +279,7 @@ func TestRealWorldNextErrorRecovery(t *testing.T) {
|
||||||
Error: "System error: Database connection timeout",
|
Error: "System error: Database connection timeout",
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Next(ctx, payload)
|
response, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Next hook failed: %v", err)
|
t.Fatalf("Next hook failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +328,7 @@ func TestRealWorldNextConditional(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Next(ctx, payload)
|
response, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Next hook failed: %v", err)
|
t.Fatalf("Next hook failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -361,7 +361,7 @@ func TestRealWorldNextConditional(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Next(ctx, payload)
|
response, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Next hook failed: %v", err)
|
t.Fatalf("Next hook failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -405,7 +405,7 @@ func TestRealWorldNextDefault(t *testing.T) {
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Next(ctx, payload)
|
response, _, err := agent.HookScript.Next(ctx, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Next hook failed: %v", err)
|
t.Fatalf("Next hook failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func TestRealWorldSimpleScenario(t *testing.T) {
|
||||||
{Role: "user", Content: "simple"},
|
{Role: "user", Content: "simple"},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Create failed: %v", err)
|
t.Fatalf("Create failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ func TestRealWorldMCPScenarios(t *testing.T) {
|
||||||
{Role: "user", Content: "mcp_health"},
|
{Role: "user", Content: "mcp_health"},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Create failed: %v", err)
|
t.Fatalf("Create failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +117,7 @@ func TestRealWorldMCPScenarios(t *testing.T) {
|
||||||
{Role: "user", Content: "mcp_tools"},
|
{Role: "user", Content: "mcp_tools"},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Create failed: %v", err)
|
t.Fatalf("Create failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -170,7 +170,7 @@ func TestRealWorldMCPScenarios(t *testing.T) {
|
||||||
{Role: "user", Content: "full_workflow"},
|
{Role: "user", Content: "full_workflow"},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Create failed: %v", err)
|
t.Fatalf("Create failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -245,7 +245,7 @@ func TestRealWorldTraceIntensive(t *testing.T) {
|
||||||
{Role: "user", Content: "trace_intensive"},
|
{Role: "user", Content: "trace_intensive"},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Create failed: %v", err)
|
t.Fatalf("Create failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -279,7 +279,7 @@ func TestRealWorldStressSimple(t *testing.T) {
|
||||||
{Role: "user", Content: "simple"},
|
{Role: "user", Content: "simple"},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Iteration %d failed: %v", i, err)
|
t.Fatalf("Iteration %d failed: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
@ -345,7 +345,7 @@ func TestRealWorldStressMCP(t *testing.T) {
|
||||||
{Role: "user", Content: scenario},
|
{Role: "user", Content: scenario},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Iteration %d (%s) failed: %v", i, scenario, err)
|
t.Fatalf("Iteration %d (%s) failed: %v", i, scenario, err)
|
||||||
}
|
}
|
||||||
|
|
@ -434,7 +434,7 @@ func TestRealWorldStressFullWorkflow(t *testing.T) {
|
||||||
{Role: "user", Content: "full_workflow"},
|
{Role: "user", Content: "full_workflow"},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Iteration %d failed: %v", i, err)
|
t.Fatalf("Iteration %d failed: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
@ -538,7 +538,7 @@ func TestRealWorldStressConcurrent(t *testing.T) {
|
||||||
{Role: "user", Content: scenario},
|
{Role: "user", Content: scenario},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors <- fmt.Errorf("goroutine %d iteration %d (%s): %v", goroutineID, i, scenario, err)
|
errors <- fmt.Errorf("goroutine %d iteration %d (%s): %v", goroutineID, i, scenario, err)
|
||||||
done()
|
done()
|
||||||
|
|
@ -665,7 +665,7 @@ func TestRealWorldStressResourceHeavy(t *testing.T) {
|
||||||
{Role: "user", Content: "resource_heavy"},
|
{Role: "user", Content: "resource_heavy"},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _, err := agent.Script.Create(ctx, messages)
|
response, _, err := agent.HookScript.Create(ctx, messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Iteration %d failed: %v", i, err)
|
t.Fatalf("Iteration %d failed: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ func LoadStore(id string) (*Assistant, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
assistant.Script = script
|
assistant.HookScript = script
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the assistant
|
// Initialize the assistant
|
||||||
|
|
@ -696,11 +696,11 @@ func loadMap(data map[string]interface{}) (*Assistant, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
assistant.Script = &hook.Script{Script: script}
|
assistant.HookScript = &hook.Script{Script: script}
|
||||||
case *hook.Script:
|
case *hook.Script:
|
||||||
assistant.Script = v
|
assistant.HookScript = v
|
||||||
case *v8.Script:
|
case *v8.Script:
|
||||||
assistant.Script = &hook.Script{Script: v}
|
assistant.HookScript = &hook.Script{Script: v}
|
||||||
}
|
}
|
||||||
} else if assistant.Source != "" {
|
} else if assistant.Source != "" {
|
||||||
// Load from source field if script is not provided
|
// Load from source field if script is not provided
|
||||||
|
|
@ -708,7 +708,7 @@ func loadMap(data map[string]interface{}) (*Assistant, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
assistant.Script = script
|
assistant.HookScript = script
|
||||||
}
|
}
|
||||||
|
|
||||||
// created_at
|
// created_at
|
||||||
|
|
@ -783,8 +783,8 @@ func (ast *Assistant) initialize() error {
|
||||||
ast.openai = api
|
ast.openai = api
|
||||||
|
|
||||||
// Check if the assistant has an init hook
|
// Check if the assistant has an init hook
|
||||||
if ast.Script != nil {
|
if ast.HookScript != nil {
|
||||||
scriptCtx, err := ast.Script.NewContext("", nil)
|
scriptCtx, err := ast.HookScript.NewContext("", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ function Create(ctx, messages) {
|
||||||
assert.Contains(t, loaded.Tags, "Source")
|
assert.Contains(t, loaded.Tags, "Source")
|
||||||
|
|
||||||
// Verify script was compiled from source
|
// Verify script was compiled from source
|
||||||
assert.NotNil(t, loaded.Script, "Script should be compiled from Source field")
|
assert.NotNil(t, loaded.HookScript, "HookScript should be compiled from Source field")
|
||||||
|
|
||||||
// Verify source is stored
|
// Verify source is stored
|
||||||
assert.NotEmpty(t, loaded.Source)
|
assert.NotEmpty(t, loaded.Source)
|
||||||
|
|
@ -170,7 +170,7 @@ func TestLoadStoreWithoutSource(t *testing.T) {
|
||||||
assert.Contains(t, loaded.Tags, "NoSource")
|
assert.Contains(t, loaded.Tags, "NoSource")
|
||||||
|
|
||||||
// Verify script is nil (no source)
|
// Verify script is nil (no source)
|
||||||
assert.Nil(t, loaded.Script, "Script should be nil when no Source field")
|
assert.Nil(t, loaded.HookScript, "HookScript should be nil when no Source field")
|
||||||
assert.Empty(t, loaded.Source)
|
assert.Empty(t, loaded.Source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,16 +259,16 @@ function Create(ctx: any, messages: any[]): any {
|
||||||
loaded, err := assistant.Get(assistantID)
|
loaded, err := assistant.Get(assistantID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, loaded)
|
require.NotNil(t, loaded)
|
||||||
require.NotNil(t, loaded.Script, "Script should be compiled from Source")
|
require.NotNil(t, loaded.HookScript, "HookScript should be compiled from Source")
|
||||||
|
|
||||||
// Verify the script object exists and is usable
|
// Verify the script object exists and is usable
|
||||||
assert.NotNil(t, loaded.Script.Script)
|
assert.NotNil(t, loaded.HookScript.Script)
|
||||||
|
|
||||||
// Execute the Create hook
|
// Execute the Create hook
|
||||||
ctx := newStoreTestContext("test-chat-id", assistantID)
|
ctx := newStoreTestContext("test-chat-id", assistantID)
|
||||||
messages := []context.Message{{Role: "user", Content: "Hello"}}
|
messages := []context.Message{{Role: "user", Content: "Hello"}}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err, "Create hook should execute without error")
|
require.NoError(t, err, "Create hook should execute without error")
|
||||||
require.NotNil(t, res, "Create hook should return a response")
|
require.NotNil(t, res, "Create hook should return a response")
|
||||||
|
|
||||||
|
|
@ -568,14 +568,14 @@ function Create(ctx: any, messages: any[]): any {
|
||||||
assert.Len(t, loaded.Placeholder.Prompts, 2)
|
assert.Len(t, loaded.Placeholder.Prompts, 2)
|
||||||
|
|
||||||
// Script from source
|
// Script from source
|
||||||
assert.NotNil(t, loaded.Script)
|
assert.NotNil(t, loaded.HookScript)
|
||||||
assert.NotEmpty(t, loaded.Source)
|
assert.NotEmpty(t, loaded.Source)
|
||||||
|
|
||||||
// Execute the Create hook to verify it works
|
// Execute the Create hook to verify it works
|
||||||
ctx := newStoreTestContext("test-chat-all-fields", assistantID)
|
ctx := newStoreTestContext("test-chat-all-fields", assistantID)
|
||||||
messages := []context.Message{{Role: "user", Content: "Test message"}}
|
messages := []context.Message{{Role: "user", Content: "Test message"}}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err, "Create hook should execute without error")
|
require.NoError(t, err, "Create hook should execute without error")
|
||||||
require.NotNil(t, res, "Create hook should return a response")
|
require.NotNil(t, res, "Create hook should return a response")
|
||||||
|
|
||||||
|
|
@ -680,7 +680,7 @@ function Create(ctx: CreateContext, messages: Message[]): CreateResponse | null
|
||||||
loaded, err := assistant.Get(assistantID)
|
loaded, err := assistant.Get(assistantID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, loaded)
|
require.NotNil(t, loaded)
|
||||||
require.NotNil(t, loaded.Script, "Script should be compiled from TypeScript Source")
|
require.NotNil(t, loaded.HookScript, "HookScript should be compiled from TypeScript Source")
|
||||||
|
|
||||||
// Execute the Create hook
|
// Execute the Create hook
|
||||||
ctx := newStoreTestContext("ts-test-chat", assistantID)
|
ctx := newStoreTestContext("ts-test-chat", assistantID)
|
||||||
|
|
@ -690,7 +690,7 @@ function Create(ctx: CreateContext, messages: Message[]): CreateResponse | null
|
||||||
{Role: "user", Content: "How are you?"},
|
{Role: "user", Content: "How are you?"},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err, "TypeScript Create hook should execute without error")
|
require.NoError(t, err, "TypeScript Create hook should execute without error")
|
||||||
require.NotNil(t, res, "Create hook should return a response")
|
require.NotNil(t, res, "Create hook should return a response")
|
||||||
|
|
||||||
|
|
@ -753,12 +753,12 @@ function Create(ctx: any, messages: any[]): any {
|
||||||
loaded, err := assistant.Get(assistantID)
|
loaded, err := assistant.Get(assistantID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, loaded)
|
require.NotNil(t, loaded)
|
||||||
require.NotNil(t, loaded.Script)
|
require.NotNil(t, loaded.HookScript)
|
||||||
|
|
||||||
ctx := newStoreTestContext("null-test-chat", assistantID)
|
ctx := newStoreTestContext("null-test-chat", assistantID)
|
||||||
messages := []context.Message{{Role: "user", Content: "Hello"}}
|
messages := []context.Message{{Role: "user", Content: "Hello"}}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err, "Hook returning null should not error")
|
require.NoError(t, err, "Hook returning null should not error")
|
||||||
assert.Nil(t, res, "Hook returning null should return nil response")
|
assert.Nil(t, res, "Hook returning null should return nil response")
|
||||||
}
|
}
|
||||||
|
|
@ -824,14 +824,14 @@ function Create(ctx: any, messages: any[]): any {
|
||||||
loaded, err := assistant.Get(assistantID)
|
loaded, err := assistant.Get(assistantID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, loaded)
|
require.NotNil(t, loaded)
|
||||||
require.NotNil(t, loaded.Script)
|
require.NotNil(t, loaded.HookScript)
|
||||||
|
|
||||||
// Test friendly preset selection
|
// Test friendly preset selection
|
||||||
t.Run("SelectFriendlyPreset", func(t *testing.T) {
|
t.Run("SelectFriendlyPreset", func(t *testing.T) {
|
||||||
ctx := newStoreTestContext("preset-test-1", assistantID)
|
ctx := newStoreTestContext("preset-test-1", assistantID)
|
||||||
messages := []context.Message{{Role: "user", Content: "Be friendly please"}}
|
messages := []context.Message{{Role: "user", Content: "Be friendly please"}}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
assert.Equal(t, "friendly", res.PromptPreset)
|
assert.Equal(t, "friendly", res.PromptPreset)
|
||||||
|
|
@ -842,7 +842,7 @@ function Create(ctx: any, messages: any[]): any {
|
||||||
ctx := newStoreTestContext("preset-test-2", assistantID)
|
ctx := newStoreTestContext("preset-test-2", assistantID)
|
||||||
messages := []context.Message{{Role: "user", Content: "Be professional"}}
|
messages := []context.Message{{Role: "user", Content: "Be professional"}}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
assert.Equal(t, "professional", res.PromptPreset)
|
assert.Equal(t, "professional", res.PromptPreset)
|
||||||
|
|
@ -853,7 +853,7 @@ function Create(ctx: any, messages: any[]): any {
|
||||||
ctx := newStoreTestContext("preset-test-3", assistantID)
|
ctx := newStoreTestContext("preset-test-3", assistantID)
|
||||||
messages := []context.Message{{Role: "user", Content: "Hello"}}
|
messages := []context.Message{{Role: "user", Content: "Hello"}}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Nil(t, res)
|
assert.Nil(t, res)
|
||||||
})
|
})
|
||||||
|
|
@ -908,14 +908,14 @@ function Create(ctx: any, messages: any[]): any {
|
||||||
loaded, err := assistant.Get(assistantID)
|
loaded, err := assistant.Get(assistantID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, loaded)
|
require.NotNil(t, loaded)
|
||||||
require.NotNil(t, loaded.Script)
|
require.NotNil(t, loaded.HookScript)
|
||||||
|
|
||||||
// Test disable global prompts
|
// Test disable global prompts
|
||||||
t.Run("DisableGlobalPrompts", func(t *testing.T) {
|
t.Run("DisableGlobalPrompts", func(t *testing.T) {
|
||||||
ctx := newStoreTestContext("disable-test-1", assistantID)
|
ctx := newStoreTestContext("disable-test-1", assistantID)
|
||||||
messages := []context.Message{{Role: "user", Content: "disable_global prompts"}}
|
messages := []context.Message{{Role: "user", Content: "disable_global prompts"}}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
require.NotNil(t, res.DisableGlobalPrompts)
|
require.NotNil(t, res.DisableGlobalPrompts)
|
||||||
|
|
@ -927,7 +927,7 @@ function Create(ctx: any, messages: any[]): any {
|
||||||
ctx := newStoreTestContext("disable-test-2", assistantID)
|
ctx := newStoreTestContext("disable-test-2", assistantID)
|
||||||
messages := []context.Message{{Role: "user", Content: "enable_global prompts"}}
|
messages := []context.Message{{Role: "user", Content: "enable_global prompts"}}
|
||||||
|
|
||||||
res, _, err := loaded.Script.Create(ctx, messages, &context.Options{})
|
res, _, err := loaded.HookScript.Create(ctx, messages, &context.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
require.NotNil(t, res.DisableGlobalPrompts)
|
require.NotNil(t, res.DisableGlobalPrompts)
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func TestLoadPath(t *testing.T) {
|
||||||
assert.Equal(t, "system", assistant.Prompts[0].Role)
|
assert.Equal(t, "system", assistant.Prompts[0].Role)
|
||||||
|
|
||||||
// Script (from src/index.ts)
|
// Script (from src/index.ts)
|
||||||
assert.NotNil(t, assistant.Script)
|
assert.NotNil(t, assistant.HookScript)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("LoadConnectorOptions", func(t *testing.T) {
|
t.Run("LoadConnectorOptions", func(t *testing.T) {
|
||||||
|
|
@ -227,8 +227,8 @@ func TestLoadPathBuildRequest(t *testing.T) {
|
||||||
assert.Equal(t, "tests.buildrequest", assistant.ID)
|
assert.Equal(t, "tests.buildrequest", assistant.ID)
|
||||||
assert.Equal(t, "Build Request Test", assistant.Name)
|
assert.Equal(t, "Build Request Test", assistant.Name)
|
||||||
|
|
||||||
// Script should be loaded
|
// HookScript should be loaded
|
||||||
assert.NotNil(t, assistant.Script)
|
assert.NotNil(t, assistant.HookScript)
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
assert.NotNil(t, assistant.Options)
|
assert.NotNil(t, assistant.Options)
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ type SearchOption struct {
|
||||||
// Assistant the assistant
|
// Assistant the assistant
|
||||||
type Assistant struct {
|
type Assistant struct {
|
||||||
store.AssistantModel
|
store.AssistantModel
|
||||||
Search *SearchOption `json:"search,omitempty" yaml:"search,omitempty"` // Whether this assistant supports search
|
Search *SearchOption `json:"search,omitempty" yaml:"search,omitempty"` // Whether this assistant supports search
|
||||||
Script *hook.Script `json:"-" yaml:"-"` // Assistant Script
|
HookScript *hook.Script `json:"-" yaml:"-"` // Hook Script
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue