@lota-sdk/core 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/package.json +2 -2
  2. package/src/ai/definitions.ts +5 -59
  3. package/src/ai-gateway/ai-gateway.ts +36 -28
  4. package/src/ai-gateway/cache-headers.ts +9 -0
  5. package/src/config/model-constants.ts +6 -2
  6. package/src/create-runtime.ts +5 -17
  7. package/src/db/memory-types.ts +13 -8
  8. package/src/db/memory.ts +74 -53
  9. package/src/queues/autonomous-job.queue.ts +1 -8
  10. package/src/queues/context-compaction.queue.ts +2 -2
  11. package/src/queues/index.ts +2 -6
  12. package/src/queues/organization-learning.queue.ts +78 -0
  13. package/src/queues/plan-agent-heartbeat.queue.ts +10 -16
  14. package/src/queues/title-generation.queue.ts +62 -0
  15. package/src/runtime/agent-prompt-context.ts +0 -18
  16. package/src/runtime/agent-runtime-policy.ts +9 -2
  17. package/src/runtime/context-compaction-constants.ts +4 -2
  18. package/src/runtime/context-compaction.ts +135 -118
  19. package/src/runtime/execution-plan.ts +2 -1
  20. package/src/runtime/memory-pipeline.ts +70 -1
  21. package/src/runtime/memory-prompts-fact.ts +16 -0
  22. package/src/runtime/plugin-resolution.ts +3 -2
  23. package/src/runtime/plugin-types.ts +1 -42
  24. package/src/runtime/post-turn-side-effects.ts +212 -0
  25. package/src/runtime/runtime-config.ts +0 -13
  26. package/src/runtime/runtime-extensions.ts +10 -16
  27. package/src/runtime/runtime-worker-registry.ts +8 -19
  28. package/src/runtime/social-chat-agent-runner.ts +119 -0
  29. package/src/runtime/social-chat-history.ts +110 -0
  30. package/src/runtime/social-chat-prompts.ts +58 -0
  31. package/src/runtime/social-chat.ts +104 -340
  32. package/src/runtime/specialist-runner.ts +18 -0
  33. package/src/runtime/workstream-chat-helpers.ts +19 -0
  34. package/src/runtime/workstream-plan-turn.ts +195 -0
  35. package/src/runtime/workstream-state.ts +11 -8
  36. package/src/runtime/workstream-turn-context.ts +183 -0
  37. package/src/services/agent-activity.service.ts +350 -0
  38. package/src/services/autonomous-job.service.ts +1 -8
  39. package/src/services/execution-plan.service.ts +205 -334
  40. package/src/services/index.ts +2 -4
  41. package/src/services/memory.service.ts +54 -44
  42. package/src/services/ownership-dispatcher.service.ts +2 -19
  43. package/src/services/plan-completion-side-effects.ts +80 -0
  44. package/src/services/plan-event-delivery.service.ts +1 -1
  45. package/src/services/plan-executor.service.ts +42 -190
  46. package/src/services/plan-node-spec.ts +60 -0
  47. package/src/services/plan-run-data.ts +88 -0
  48. package/src/services/plan-validator.service.ts +10 -8
  49. package/src/services/workstream-constants.ts +2 -0
  50. package/src/services/workstream-title.service.ts +1 -1
  51. package/src/services/workstream-turn-preparation.service.ts +208 -715
  52. package/src/services/workstream.service.ts +162 -192
  53. package/src/services/workstream.types.ts +12 -44
  54. package/src/system-agents/regular-chat-memory-digest.agent.ts +3 -0
  55. package/src/tools/execution-plan.tool.ts +11 -6
  56. package/src/tools/index.ts +1 -0
  57. package/src/tools/project-with-plan.tool.ts +87 -0
  58. package/src/tools/remember-memory.tool.ts +7 -10
  59. package/src/tools/research-topic.tool.ts +1 -1
  60. package/src/tools/team-think.tool.ts +1 -1
  61. package/src/tools/user-questions.tool.ts +1 -1
  62. package/src/utils/autonomous-job-ids.ts +7 -0
  63. package/src/workers/organization-learning.worker.ts +31 -0
  64. package/src/workers/regular-chat-memory-digest.runner.ts +9 -3
  65. package/src/workers/skill-extraction.runner.ts +2 -2
  66. package/src/queues/recent-activity-title-refinement.queue.ts +0 -30
  67. package/src/queues/regular-chat-memory-digest.config.ts +0 -12
  68. package/src/queues/regular-chat-memory-digest.queue.ts +0 -34
  69. package/src/queues/skill-extraction.config.ts +0 -9
  70. package/src/queues/skill-extraction.queue.ts +0 -27
  71. package/src/queues/workstream-title-generation.queue.ts +0 -33
  72. package/src/services/context-enrichment.service.ts +0 -33
  73. package/src/services/coordination-registry.service.ts +0 -117
  74. package/src/services/domain-agent-executor.service.ts +0 -71
  75. package/src/services/memory-assessment.service.ts +0 -44
  76. package/src/services/playbook-registry.service.ts +0 -67
  77. package/src/workers/regular-chat-memory-digest.worker.ts +0 -22
  78. package/src/workers/skill-extraction.worker.ts +0 -22
@@ -1,44 +0,0 @@
1
- import type { z } from 'zod'
2
-
3
- import { MemoryImportanceAssessmentSchema } from '../db/memory-types'
4
- import { createHelperModelRuntime } from '../runtime/helper-model'
5
- import { createOrgMemoryAgent } from '../system-agents/memory.agent'
6
- import { clampImportance } from '../utils/string'
7
-
8
- type MemoryImportanceAssessment = z.infer<typeof MemoryImportanceAssessmentSchema>
9
- const MEMORY_IMPORTANCE_ASSESSMENT_TIMEOUT_MS = 10 * 60 * 1000
10
- const helperModelRuntime = createHelperModelRuntime()
11
-
12
- export function clampMemoryImportance(value: number): number {
13
- return clampImportance(Math.max(0.2, Math.min(0.95, value)))
14
- }
15
-
16
- export async function assessMemoryImportance(params: {
17
- content: string
18
- targetScope: 'agent' | 'global'
19
- tag?: string
20
- }): Promise<MemoryImportanceAssessment> {
21
- const prompt = [
22
- 'Assess whether this memory should be persisted in long-term memory.',
23
- `targetScope: ${params.targetScope}`,
24
- `memory: ${params.content}`,
25
- '',
26
- 'Rules:',
27
- '- importance: number between 0 and 1 for long-term usefulness.',
28
- '- durability: core|standard|ephemeral.',
29
- '- classification: durable|transient|uncertain.',
30
- '- rationale: short and concrete.',
31
- '',
32
- 'The caller enforces a structured output schema.',
33
- 'Return only schema fields.',
34
- ].join('\n')
35
-
36
- return helperModelRuntime.generateHelperStructured({
37
- tag: params.tag ?? 'memory-importance-assessment',
38
- createAgent: createOrgMemoryAgent,
39
- systemPrompt: 'You are a strict long-term memory quality assessor for an AI agent.',
40
- messages: [{ role: 'user', content: prompt }],
41
- schema: MemoryImportanceAssessmentSchema,
42
- timeoutMs: MEMORY_IMPORTANCE_ASSESSMENT_TIMEOUT_MS,
43
- })
44
- }
@@ -1,67 +0,0 @@
1
- import type { PlanTemplateRecord } from '@lota-sdk/shared'
2
-
3
- import type { RecordIdInput } from '../db/record-id'
4
- import type { PlaybookContribution } from '../runtime/plugin-types'
5
- import { getRuntimeConfig } from '../runtime/runtime-config'
6
- import { planTemplateService } from './plan-template.service'
7
-
8
- class PlaybookRegistryService {
9
- collectPlaybooks(): PlaybookContribution[] {
10
- const plugins = getRuntimeConfig().pluginRuntime ?? {}
11
- const playbooks: PlaybookContribution[] = []
12
- for (const plugin of Object.values(plugins)) {
13
- if (plugin.playbookContributor?.playbooks) {
14
- playbooks.push(...plugin.playbookContributor.playbooks)
15
- }
16
- }
17
- return playbooks
18
- }
19
-
20
- async syncPlaybookTemplates(organizationId: RecordIdInput): Promise<PlanTemplateRecord[]> {
21
- const playbooks = this.collectPlaybooks()
22
- const templates: PlanTemplateRecord[] = []
23
- const existing = await planTemplateService.listTemplates(organizationId, { source: 'playbook' })
24
-
25
- for (const pb of playbooks) {
26
- const match = existing.find((t) => t.sourceRef === pb.name)
27
- if (match) {
28
- const updated = await planTemplateService.updateTemplate(match.id, { draft: pb.draft, tags: pb.tags })
29
- templates.push(updated)
30
- } else {
31
- const created = await planTemplateService.createTemplate({
32
- organizationId,
33
- name: pb.name,
34
- description: pb.description,
35
- draft: pb.draft,
36
- tags: pb.tags,
37
- source: 'playbook',
38
- sourceRef: pb.name,
39
- })
40
- templates.push(created)
41
- }
42
- }
43
-
44
- return templates
45
- }
46
-
47
- async instantiatePlaybook(params: {
48
- name: string
49
- organizationId: RecordIdInput
50
- workstreamId: RecordIdInput
51
- leadAgentId: string
52
- }): Promise<unknown> {
53
- const templates = await planTemplateService.listTemplates(params.organizationId, { source: 'playbook' })
54
- const template = templates.find((t) => t.sourceRef === params.name)
55
- if (!template) {
56
- throw new Error(`Playbook "${params.name}" not found.`)
57
- }
58
- return planTemplateService.instantiate({
59
- templateId: template.id,
60
- organizationId: params.organizationId,
61
- workstreamId: params.workstreamId,
62
- leadAgentId: params.leadAgentId,
63
- })
64
- }
65
- }
66
-
67
- export const playbookRegistryService = new PlaybookRegistryService()
@@ -1,22 +0,0 @@
1
- import type { SandboxedJob } from 'bullmq'
2
-
3
- import { serverLogger } from '../config/logger'
4
- import type { RegularChatMemoryDigestJob } from '../queues/regular-chat-memory-digest.queue'
5
- import { initializeSandboxedWorkerRuntime } from './bootstrap'
6
- import { runRegularChatMemoryDigest } from './regular-chat-memory-digest.runner'
7
- import { toSandboxedWorkerError } from './utils/sandbox-error'
8
- import { createTracedWorkerProcessor } from './worker-utils'
9
-
10
- await initializeSandboxedWorkerRuntime()
11
-
12
- const handler = async (job: SandboxedJob<RegularChatMemoryDigestJob>) => {
13
- try {
14
- await runRegularChatMemoryDigest(job.data)
15
- } catch (error) {
16
- const serialized = toSandboxedWorkerError(error, 'Regular chat memory digest failed')
17
- serverLogger.error`${serialized.message}`
18
- throw serialized
19
- }
20
- }
21
-
22
- export default createTracedWorkerProcessor('regular-chat-memory-digest', handler)
@@ -1,22 +0,0 @@
1
- import type { SandboxedJob } from 'bullmq'
2
-
3
- import { serverLogger } from '../config/logger'
4
- import type { SkillExtractionJob } from '../queues/skill-extraction.queue'
5
- import { initializeSandboxedWorkerRuntime } from './bootstrap'
6
- import { runSkillExtraction } from './skill-extraction.runner'
7
- import { toSandboxedWorkerError } from './utils/sandbox-error'
8
- import { createTracedWorkerProcessor } from './worker-utils'
9
-
10
- await initializeSandboxedWorkerRuntime()
11
-
12
- const handler = async (job: SandboxedJob<SkillExtractionJob>) => {
13
- try {
14
- await runSkillExtraction(job.data)
15
- } catch (error) {
16
- const serialized = toSandboxedWorkerError(error, 'Skill extraction failed')
17
- serverLogger.error`${serialized.message}`
18
- throw serialized
19
- }
20
- }
21
-
22
- export default createTracedWorkerProcessor('skill-extraction', handler)