lingxios 1.0.0
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/README.md +54 -0
- package/db/schema.sql +306 -0
- package/dist/src/app/artifacts.d.ts +8 -0
- package/dist/src/app/artifacts.js +114 -0
- package/dist/src/app/artifacts.js.map +1 -0
- package/dist/src/app/doctor.d.ts +22 -0
- package/dist/src/app/doctor.js +44 -0
- package/dist/src/app/doctor.js.map +1 -0
- package/dist/src/app/index.d.ts +123 -0
- package/dist/src/app/index.js +291 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/input.d.ts +22 -0
- package/dist/src/app/input.js +60 -0
- package/dist/src/app/input.js.map +1 -0
- package/dist/src/app/recover-wait.d.ts +5 -0
- package/dist/src/app/recover-wait.js +59 -0
- package/dist/src/app/recover-wait.js.map +1 -0
- package/dist/src/app/resources.d.ts +5 -0
- package/dist/src/app/resources.js +9 -0
- package/dist/src/app/resources.js.map +1 -0
- package/dist/src/app/storage.d.ts +2 -0
- package/dist/src/app/storage.js +41 -0
- package/dist/src/app/storage.js.map +1 -0
- package/dist/src/cli/doctor.d.ts +2 -0
- package/dist/src/cli/doctor.js +20 -0
- package/dist/src/cli/doctor.js.map +1 -0
- package/dist/src/cli/eval.d.ts +2 -0
- package/dist/src/cli/eval.js +44 -0
- package/dist/src/cli/eval.js.map +1 -0
- package/dist/src/config.d.ts +22 -0
- package/dist/src/config.js +56 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/context/attachments.d.ts +10 -0
- package/dist/src/context/attachments.js +18 -0
- package/dist/src/context/attachments.js.map +1 -0
- package/dist/src/context/document-text.d.ts +1 -0
- package/dist/src/context/document-text.js +29 -0
- package/dist/src/context/document-text.js.map +1 -0
- package/dist/src/context/document-worker.d.ts +1 -0
- package/dist/src/context/document-worker.js +62 -0
- package/dist/src/context/document-worker.js.map +1 -0
- package/dist/src/context/evidence.d.ts +19 -0
- package/dist/src/context/evidence.js +37 -0
- package/dist/src/context/evidence.js.map +1 -0
- package/dist/src/context/request.d.ts +21 -0
- package/dist/src/context/request.js +32 -0
- package/dist/src/context/request.js.map +1 -0
- package/dist/src/context/research-evidence.d.ts +4 -0
- package/dist/src/context/research-evidence.js +24 -0
- package/dist/src/context/research-evidence.js.map +1 -0
- package/dist/src/context/resource-checks.d.ts +7 -0
- package/dist/src/context/resource-checks.js +15 -0
- package/dist/src/context/resource-checks.js.map +1 -0
- package/dist/src/context/task-contract.d.ts +11 -0
- package/dist/src/context/task-contract.js +23 -0
- package/dist/src/context/task-contract.js.map +1 -0
- package/dist/src/context/text.d.ts +2 -0
- package/dist/src/context/text.js +7 -0
- package/dist/src/context/text.js.map +1 -0
- package/dist/src/control-plane/http-server.d.ts +22 -0
- package/dist/src/control-plane/http-server.js +196 -0
- package/dist/src/control-plane/http-server.js.map +1 -0
- package/dist/src/control-plane/memory-store.d.ts +71 -0
- package/dist/src/control-plane/memory-store.js +389 -0
- package/dist/src/control-plane/memory-store.js.map +1 -0
- package/dist/src/control-plane/pg-store.d.ts +62 -0
- package/dist/src/control-plane/pg-store.js +386 -0
- package/dist/src/control-plane/pg-store.js.map +1 -0
- package/dist/src/control-plane/service.d.ts +52 -0
- package/dist/src/control-plane/service.js +630 -0
- package/dist/src/control-plane/service.js.map +1 -0
- package/dist/src/control-plane/stores.d.ts +184 -0
- package/dist/src/control-plane/stores.js +19 -0
- package/dist/src/control-plane/stores.js.map +1 -0
- package/dist/src/errors.d.ts +66 -0
- package/dist/src/errors.js +102 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/eval/calibration.d.ts +16 -0
- package/dist/src/eval/calibration.js +28 -0
- package/dist/src/eval/calibration.js.map +1 -0
- package/dist/src/eval/index.d.ts +40 -0
- package/dist/src/eval/index.js +40 -0
- package/dist/src/eval/index.js.map +1 -0
- package/dist/src/eval/review.d.ts +20 -0
- package/dist/src/eval/review.js +49 -0
- package/dist/src/eval/review.js.map +1 -0
- package/dist/src/host/http-client.d.ts +48 -0
- package/dist/src/host/http-client.js +127 -0
- package/dist/src/host/http-client.js.map +1 -0
- package/dist/src/host/port.d.ts +26 -0
- package/dist/src/host/port.js +2 -0
- package/dist/src/host/port.js.map +1 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/integrations/lingxiloop/actions.d.ts +25 -0
- package/dist/src/integrations/lingxiloop/actions.js +77 -0
- package/dist/src/integrations/lingxiloop/actions.js.map +1 -0
- package/dist/src/integrations/lingxiloop/app.d.ts +167 -0
- package/dist/src/integrations/lingxiloop/app.js +434 -0
- package/dist/src/integrations/lingxiloop/app.js.map +1 -0
- package/dist/src/integrations/lingxiloop/approvals.d.ts +148 -0
- package/dist/src/integrations/lingxiloop/approvals.js +540 -0
- package/dist/src/integrations/lingxiloop/approvals.js.map +1 -0
- package/dist/src/integrations/lingxiloop/attachments.d.ts +8 -0
- package/dist/src/integrations/lingxiloop/attachments.js +38 -0
- package/dist/src/integrations/lingxiloop/attachments.js.map +1 -0
- package/dist/src/integrations/lingxiloop/calendar-approvals.d.ts +21 -0
- package/dist/src/integrations/lingxiloop/calendar-approvals.js +126 -0
- package/dist/src/integrations/lingxiloop/calendar-approvals.js.map +1 -0
- package/dist/src/integrations/lingxiloop/calendar-writes.d.ts +15 -0
- package/dist/src/integrations/lingxiloop/calendar-writes.js +79 -0
- package/dist/src/integrations/lingxiloop/calendar-writes.js.map +1 -0
- package/dist/src/integrations/lingxiloop/calendar.d.ts +19 -0
- package/dist/src/integrations/lingxiloop/calendar.js +43 -0
- package/dist/src/integrations/lingxiloop/calendar.js.map +1 -0
- package/dist/src/integrations/lingxiloop/canvas-events.d.ts +7 -0
- package/dist/src/integrations/lingxiloop/canvas-events.js +53 -0
- package/dist/src/integrations/lingxiloop/canvas-events.js.map +1 -0
- package/dist/src/integrations/lingxiloop/canvas-summary.d.ts +5 -0
- package/dist/src/integrations/lingxiloop/canvas-summary.js +52 -0
- package/dist/src/integrations/lingxiloop/canvas-summary.js.map +1 -0
- package/dist/src/integrations/lingxiloop/canvas-work-report.d.ts +12 -0
- package/dist/src/integrations/lingxiloop/canvas-work-report.js +120 -0
- package/dist/src/integrations/lingxiloop/canvas-work-report.js.map +1 -0
- package/dist/src/integrations/lingxiloop/canvas-work.d.ts +11 -0
- package/dist/src/integrations/lingxiloop/canvas-work.js +306 -0
- package/dist/src/integrations/lingxiloop/canvas-work.js.map +1 -0
- package/dist/src/integrations/lingxiloop/canvas.d.ts +12 -0
- package/dist/src/integrations/lingxiloop/canvas.js +79 -0
- package/dist/src/integrations/lingxiloop/canvas.js.map +1 -0
- package/dist/src/integrations/lingxiloop/chat.d.ts +11 -0
- package/dist/src/integrations/lingxiloop/chat.js +46 -0
- package/dist/src/integrations/lingxiloop/chat.js.map +1 -0
- package/dist/src/integrations/lingxiloop/document-approvals.d.ts +21 -0
- package/dist/src/integrations/lingxiloop/document-approvals.js +75 -0
- package/dist/src/integrations/lingxiloop/document-approvals.js.map +1 -0
- package/dist/src/integrations/lingxiloop/document-content.d.ts +80 -0
- package/dist/src/integrations/lingxiloop/document-content.js +195 -0
- package/dist/src/integrations/lingxiloop/document-content.js.map +1 -0
- package/dist/src/integrations/lingxiloop/document-writes.d.ts +8 -0
- package/dist/src/integrations/lingxiloop/document-writes.js +49 -0
- package/dist/src/integrations/lingxiloop/document-writes.js.map +1 -0
- package/dist/src/integrations/lingxiloop/documents.d.ts +22 -0
- package/dist/src/integrations/lingxiloop/documents.js +38 -0
- package/dist/src/integrations/lingxiloop/documents.js.map +1 -0
- package/dist/src/integrations/lingxiloop/event-outbox.d.ts +5 -0
- package/dist/src/integrations/lingxiloop/event-outbox.js +47 -0
- package/dist/src/integrations/lingxiloop/event-outbox.js.map +1 -0
- package/dist/src/integrations/lingxiloop/index.d.ts +3 -0
- package/dist/src/integrations/lingxiloop/index.js +3 -0
- package/dist/src/integrations/lingxiloop/index.js.map +1 -0
- package/dist/src/integrations/lingxiloop/learning-attempts.d.ts +13 -0
- package/dist/src/integrations/lingxiloop/learning-attempts.js +58 -0
- package/dist/src/integrations/lingxiloop/learning-attempts.js.map +1 -0
- package/dist/src/integrations/lingxiloop/learning-evaluation.d.ts +8 -0
- package/dist/src/integrations/lingxiloop/learning-evaluation.js +64 -0
- package/dist/src/integrations/lingxiloop/learning-evaluation.js.map +1 -0
- package/dist/src/integrations/lingxiloop/learning-evidence.d.ts +7 -0
- package/dist/src/integrations/lingxiloop/learning-evidence.js +88 -0
- package/dist/src/integrations/lingxiloop/learning-evidence.js.map +1 -0
- package/dist/src/integrations/lingxiloop/learning-missions.d.ts +18 -0
- package/dist/src/integrations/lingxiloop/learning-missions.js +95 -0
- package/dist/src/integrations/lingxiloop/learning-missions.js.map +1 -0
- package/dist/src/integrations/lingxiloop/learning.d.ts +22 -0
- package/dist/src/integrations/lingxiloop/learning.js +150 -0
- package/dist/src/integrations/lingxiloop/learning.js.map +1 -0
- package/dist/src/integrations/lingxiloop/memory.d.ts +14 -0
- package/dist/src/integrations/lingxiloop/memory.js +133 -0
- package/dist/src/integrations/lingxiloop/memory.js.map +1 -0
- package/dist/src/integrations/lingxiloop/polls.d.ts +9 -0
- package/dist/src/integrations/lingxiloop/polls.js +47 -0
- package/dist/src/integrations/lingxiloop/polls.js.map +1 -0
- package/dist/src/integrations/lingxiloop/presentations.d.ts +11 -0
- package/dist/src/integrations/lingxiloop/presentations.js +34 -0
- package/dist/src/integrations/lingxiloop/presentations.js.map +1 -0
- package/dist/src/integrations/lingxiloop/questionnaire.d.ts +21 -0
- package/dist/src/integrations/lingxiloop/questionnaire.js +57 -0
- package/dist/src/integrations/lingxiloop/questionnaire.js.map +1 -0
- package/dist/src/integrations/lingxiloop/research.d.ts +19 -0
- package/dist/src/integrations/lingxiloop/research.js +20 -0
- package/dist/src/integrations/lingxiloop/research.js.map +1 -0
- package/dist/src/integrations/lingxiloop/routines.d.ts +91 -0
- package/dist/src/integrations/lingxiloop/routines.js +198 -0
- package/dist/src/integrations/lingxiloop/routines.js.map +1 -0
- package/dist/src/integrations/lingxiloop/service-contracts.d.ts +1045 -0
- package/dist/src/integrations/lingxiloop/service-contracts.js +2 -0
- package/dist/src/integrations/lingxiloop/service-contracts.js.map +1 -0
- package/dist/src/integrations/lingxiloop/teacher-context.d.ts +32 -0
- package/dist/src/integrations/lingxiloop/teacher-context.js +25 -0
- package/dist/src/integrations/lingxiloop/teacher-context.js.map +1 -0
- package/dist/src/integrations/lingxiloop/teacher-digest.d.ts +13 -0
- package/dist/src/integrations/lingxiloop/teacher-digest.js +152 -0
- package/dist/src/integrations/lingxiloop/teacher-digest.js.map +1 -0
- package/dist/src/integrations/lingxiloop/teacher-preview.d.ts +22 -0
- package/dist/src/integrations/lingxiloop/teacher-preview.js +41 -0
- package/dist/src/integrations/lingxiloop/teacher-preview.js.map +1 -0
- package/dist/src/integrations/lingxiloop/teacher.d.ts +24 -0
- package/dist/src/integrations/lingxiloop/teacher.js +224 -0
- package/dist/src/integrations/lingxiloop/teacher.js.map +1 -0
- package/dist/src/kernel/manager.d.ts +52 -0
- package/dist/src/kernel/manager.js +407 -0
- package/dist/src/kernel/manager.js.map +1 -0
- package/dist/src/logging.d.ts +21 -0
- package/dist/src/logging.js +54 -0
- package/dist/src/logging.js.map +1 -0
- package/dist/src/memory/evidence.d.ts +6 -0
- package/dist/src/memory/evidence.js +43 -0
- package/dist/src/memory/evidence.js.map +1 -0
- package/dist/src/memory/processor.d.ts +3 -0
- package/dist/src/memory/processor.js +66 -0
- package/dist/src/memory/processor.js.map +1 -0
- package/dist/src/memory/semantic.d.ts +19 -0
- package/dist/src/memory/semantic.js +93 -0
- package/dist/src/memory/semantic.js.map +1 -0
- package/dist/src/memory/store.d.ts +20 -0
- package/dist/src/memory/store.js +34 -0
- package/dist/src/memory/store.js.map +1 -0
- package/dist/src/memory/synthesis.d.ts +24 -0
- package/dist/src/memory/synthesis.js +138 -0
- package/dist/src/memory/synthesis.js.map +1 -0
- package/dist/src/metrics.d.ts +43 -0
- package/dist/src/metrics.js +130 -0
- package/dist/src/metrics.js.map +1 -0
- package/dist/src/model/driver.d.ts +60 -0
- package/dist/src/model/driver.js +2 -0
- package/dist/src/model/driver.js.map +1 -0
- package/dist/src/model/embeddings.d.ts +24 -0
- package/dist/src/model/embeddings.js +97 -0
- package/dist/src/model/embeddings.js.map +1 -0
- package/dist/src/model/openai.d.ts +45 -0
- package/dist/src/model/openai.js +340 -0
- package/dist/src/model/openai.js.map +1 -0
- package/dist/src/outcome/assessment.d.ts +16 -0
- package/dist/src/outcome/assessment.js +45 -0
- package/dist/src/outcome/assessment.js.map +1 -0
- package/dist/src/outcome/content-check.d.ts +19 -0
- package/dist/src/outcome/content-check.js +44 -0
- package/dist/src/outcome/content-check.js.map +1 -0
- package/dist/src/outcome/envelope.d.ts +34 -0
- package/dist/src/outcome/envelope.js +42 -0
- package/dist/src/outcome/envelope.js.map +1 -0
- package/dist/src/protocol/constants.d.ts +25 -0
- package/dist/src/protocol/constants.js +26 -0
- package/dist/src/protocol/constants.js.map +1 -0
- package/dist/src/protocol/kernel-wire.d.ts +74 -0
- package/dist/src/protocol/kernel-wire.js +2 -0
- package/dist/src/protocol/kernel-wire.js.map +1 -0
- package/dist/src/protocol/outcome.d.ts +16 -0
- package/dist/src/protocol/outcome.js +14 -0
- package/dist/src/protocol/outcome.js.map +1 -0
- package/dist/src/protocol/types.d.ts +266 -0
- package/dist/src/protocol/types.js +19 -0
- package/dist/src/protocol/types.js.map +1 -0
- package/dist/src/research/address.d.ts +2 -0
- package/dist/src/research/address.js +32 -0
- package/dist/src/research/address.js.map +1 -0
- package/dist/src/research/fetch.d.ts +7 -0
- package/dist/src/research/fetch.js +83 -0
- package/dist/src/research/fetch.js.map +1 -0
- package/dist/src/research/index.d.ts +26 -0
- package/dist/src/research/index.js +109 -0
- package/dist/src/research/index.js.map +1 -0
- package/dist/src/runtime/compaction.d.ts +41 -0
- package/dist/src/runtime/compaction.js +86 -0
- package/dist/src/runtime/compaction.js.map +1 -0
- package/dist/src/runtime/corrections.d.ts +20 -0
- package/dist/src/runtime/corrections.js +27 -0
- package/dist/src/runtime/corrections.js.map +1 -0
- package/dist/src/runtime/policy.d.ts +42 -0
- package/dist/src/runtime/policy.js +91 -0
- package/dist/src/runtime/policy.js.map +1 -0
- package/dist/src/runtime/resource-refresh.d.ts +8 -0
- package/dist/src/runtime/resource-refresh.js +37 -0
- package/dist/src/runtime/resource-refresh.js.map +1 -0
- package/dist/src/runtime/runtime.d.ts +51 -0
- package/dist/src/runtime/runtime.js +804 -0
- package/dist/src/runtime/runtime.js.map +1 -0
- package/dist/src/runtime/tool.d.ts +13 -0
- package/dist/src/runtime/tool.js +42 -0
- package/dist/src/runtime/tool.js.map +1 -0
- package/dist/src/ui/index.d.ts +27 -0
- package/dist/src/ui/index.js +54 -0
- package/dist/src/ui/index.js.map +1 -0
- package/dist/src/versions.d.ts +9 -0
- package/dist/src/versions.js +11 -0
- package/dist/src/versions.js.map +1 -0
- package/dist/src/worker/index.d.ts +3 -0
- package/dist/src/worker/index.js +57 -0
- package/dist/src/worker/index.js.map +1 -0
- package/dist/src/worker/main.d.ts +2 -0
- package/dist/src/worker/main.js +9 -0
- package/dist/src/worker/main.js.map +1 -0
- package/dist/src/worker/worker.d.ts +45 -0
- package/dist/src/worker/worker.js +154 -0
- package/dist/src/worker/worker.js.map +1 -0
- package/kernel/runner.py +507 -0
- package/package.json +83 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { nativeWork } from './actions.js';
|
|
2
|
+
export const LEARNING_METHODS = { list_attempts: ['activityId', 'missionStepId'], get_attempt: ['attemptId'], propose_evaluation: ['attemptId', 'demonstratedLevel', 'confidence', 'rubricResults', 'feedback', 'sourceEvidenceId', 'verifierEvidenceId'], record_attempt: ['activityId', 'missionStepId', 'evidenceClientMsgNos', 'documentIds', 'canvasFrameIds', 'assistance'], draft_knowledge_units: ['knowledgeUnits'], draft_activity: ['title', 'instructions', 'kind', 'evaluationMode', 'targetLevel', 'rubric', 'knowledgeUnitIds', 'dueAt'], start_mission: ['goal', 'successCriteria', 'missionKind', 'sourceClientMsgNo', 'explicit'], update_step: ['missionId', 'stepId', 'status', 'outcome', 'sourceEvidenceId', 'attemptId'], add_steps: ['missionId', 'steps'], finish_planning: ['missionId'], complete_mission: ['missionId'], current: [], get_learner_state: [], list_knowledge_units: [], list_due: [], get_mission: ['missionId'], get_activity: ['activityId'] };
|
|
3
|
+
function draftText(value) {
|
|
4
|
+
if (typeof value !== 'string' || !value.trim() || value.length > 10000)
|
|
5
|
+
throw new Error('draft text must contain 1 to 10000 characters');
|
|
6
|
+
return value.trim();
|
|
7
|
+
}
|
|
8
|
+
function draftLevel(value) {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
if (!Number.isInteger(value) || Number(value) < 1 || Number(value) > 4)
|
|
12
|
+
throw new Error('targetLevel must be 1-4');
|
|
13
|
+
return Number(value);
|
|
14
|
+
}
|
|
15
|
+
function draftIds(value) {
|
|
16
|
+
if (value === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
if (!Array.isArray(value) || value.length > 100)
|
|
19
|
+
throw new Error('draft ID lists are limited to 100 items');
|
|
20
|
+
const ids = value.map(draftText);
|
|
21
|
+
if (new Set(ids).size !== ids.length)
|
|
22
|
+
throw new Error('draft IDs must be unique');
|
|
23
|
+
return ids;
|
|
24
|
+
}
|
|
25
|
+
export async function executeLearning(work, action, services) {
|
|
26
|
+
const api = services.learning;
|
|
27
|
+
const method = action.action.slice('learning.'.length);
|
|
28
|
+
if (!api || !action.action.startsWith('learning.') || !Object.hasOwn(LEARNING_METHODS, method))
|
|
29
|
+
throw new Error('unsupported learning action');
|
|
30
|
+
const allowed = LEARNING_METHODS[method];
|
|
31
|
+
if (Object.keys(action.args).some(key => !allowed.includes(key)))
|
|
32
|
+
throw new Error('unknown learning argument');
|
|
33
|
+
const native = nativeWork(work);
|
|
34
|
+
await services.permissionService.assertCan({ actorUserId: native.authorizationUserId, companyId: native.companyId, action: method === 'draft_knowledge_units' || method === 'draft_activity' || method === 'update_step' || method === 'add_steps' || method === 'finish_planning' || method === 'complete_mission' ? 'learning:submit' : 'learning:read', resource: { type: 'conversation', id: native.channelId } });
|
|
35
|
+
const context = await api.loadLearningTurnContext(native, native.authorizationUserId);
|
|
36
|
+
if (!context)
|
|
37
|
+
throw new Error('conversation is not bound to a learning project');
|
|
38
|
+
switch (method) {
|
|
39
|
+
case 'draft_knowledge_units':
|
|
40
|
+
case 'draft_activity': {
|
|
41
|
+
await services.permissionService.assertCan({ actorUserId: native.authorizationUserId, companyId: native.companyId,
|
|
42
|
+
action: 'learning:submit', resource: { type: 'project', id: context.project.id } });
|
|
43
|
+
const scope = { companyId: work.tenantId, projectId: context.project.id, actorId: work.agentId, actorKind: 'agent' };
|
|
44
|
+
if (method === 'draft_knowledge_units') {
|
|
45
|
+
const units = action.args['knowledgeUnits'];
|
|
46
|
+
if (!Array.isArray(units) || !units.length || units.length > 100)
|
|
47
|
+
throw new Error('knowledgeUnits must contain 1 to 100 items');
|
|
48
|
+
const knowledgeUnits = units.map(value => {
|
|
49
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
50
|
+
throw new Error('invalid knowledge unit');
|
|
51
|
+
const item = value;
|
|
52
|
+
if (Object.keys(item).some(key => !['title', 'successCriteria', 'targetLevel', 'prerequisiteKnowledgeUnitIds'].includes(key)))
|
|
53
|
+
throw new Error('unknown knowledge unit field');
|
|
54
|
+
const targetLevel = draftLevel(item['targetLevel']), prerequisiteKnowledgeUnitIds = draftIds(item['prerequisiteKnowledgeUnitIds']);
|
|
55
|
+
return { title: draftText(item['title']), successCriteria: draftText(item['successCriteria']),
|
|
56
|
+
...(targetLevel === undefined ? {} : { targetLevel }), ...(prerequisiteKnowledgeUnitIds === undefined ? {} : { prerequisiteKnowledgeUnitIds }) };
|
|
57
|
+
});
|
|
58
|
+
return api.createKnowledgeUnits({ ...scope, knowledgeUnits });
|
|
59
|
+
}
|
|
60
|
+
const { kind, evaluationMode, rubric, dueAt } = action.args;
|
|
61
|
+
if (kind !== 'LESSON' && kind !== 'PRACTICE' && kind !== 'ASSESSMENT' && kind !== 'PROJECT' && kind !== 'REVIEW')
|
|
62
|
+
throw new Error('invalid activity kind');
|
|
63
|
+
if (evaluationMode !== undefined && evaluationMode !== 'AGENT_FORMATIVE' && evaluationMode !== 'TEACHER_REQUIRED')
|
|
64
|
+
throw new Error('invalid evaluationMode');
|
|
65
|
+
if (rubric !== undefined && (!Array.isArray(rubric) || rubric.length > 100))
|
|
66
|
+
throw new Error('rubric is limited to 100 items');
|
|
67
|
+
if (dueAt !== undefined && (typeof dueAt !== 'string' || dueAt.length > 100 || !Number.isFinite(Date.parse(dueAt))))
|
|
68
|
+
throw new Error('invalid dueAt');
|
|
69
|
+
const targetLevel = draftLevel(action.args['targetLevel']), knowledgeUnitIds = draftIds(action.args['knowledgeUnitIds']);
|
|
70
|
+
return api.draftActivity({ ...scope, title: draftText(action.args['title']), instructions: draftText(action.args['instructions']), kind,
|
|
71
|
+
...(evaluationMode === undefined ? {} : { evaluationMode }), ...(targetLevel === undefined ? {} : { targetLevel }),
|
|
72
|
+
...(rubric === undefined ? {} : { rubric }), ...(knowledgeUnitIds === undefined ? {} : { knowledgeUnitIds }), ...(dueAt === undefined ? {} : { dueAt }) });
|
|
73
|
+
}
|
|
74
|
+
case 'current':
|
|
75
|
+
case 'get_learner_state': return context;
|
|
76
|
+
case 'list_knowledge_units': return context.knowledgeUnits;
|
|
77
|
+
case 'list_due': return context.due;
|
|
78
|
+
case 'get_mission': {
|
|
79
|
+
const id = action.args['missionId'];
|
|
80
|
+
if (id === undefined)
|
|
81
|
+
return context.activeMission ?? null;
|
|
82
|
+
if (typeof id !== 'string' || !id.trim())
|
|
83
|
+
throw new Error('missionId must be non-empty');
|
|
84
|
+
if (!context.learnerId)
|
|
85
|
+
throw new Error('current learning room has no learner scope');
|
|
86
|
+
return api.getMission(id, work.tenantId, context.project.id, context.learnerId, work.sessionId);
|
|
87
|
+
}
|
|
88
|
+
case 'update_step':
|
|
89
|
+
case 'add_steps':
|
|
90
|
+
case 'finish_planning':
|
|
91
|
+
case 'complete_mission': {
|
|
92
|
+
const id = action.args['missionId'];
|
|
93
|
+
if (typeof id !== 'string' || !id.trim())
|
|
94
|
+
throw new Error('missionId must be non-empty');
|
|
95
|
+
if (!context.learnerId)
|
|
96
|
+
throw new Error('current learning room has no learner scope');
|
|
97
|
+
await api.getMission(id, work.tenantId, context.project.id, context.learnerId, work.sessionId);
|
|
98
|
+
if (method === 'update_step') {
|
|
99
|
+
const stepId = action.args['stepId'], status = action.args['status'];
|
|
100
|
+
if (typeof stepId !== 'string' || !stepId.trim())
|
|
101
|
+
throw new Error('stepId must be non-empty');
|
|
102
|
+
if (status !== 'OPEN' && status !== 'IN_PROGRESS' && status !== 'COMPLETED' && status !== 'CANCELLED')
|
|
103
|
+
throw new Error('invalid step status');
|
|
104
|
+
const input = { missionId: id, stepId, status };
|
|
105
|
+
for (const key of ['outcome', 'sourceEvidenceId', 'attemptId']) {
|
|
106
|
+
const value = action.args[key];
|
|
107
|
+
if (value === undefined)
|
|
108
|
+
continue;
|
|
109
|
+
if (typeof value !== 'string' || !value.trim() || value.length > 10_000)
|
|
110
|
+
throw new Error(`${key} must contain 1 to 10000 characters`);
|
|
111
|
+
input[key] = value;
|
|
112
|
+
}
|
|
113
|
+
return api.updateMissionStep(native, input);
|
|
114
|
+
}
|
|
115
|
+
if (method === 'add_steps') {
|
|
116
|
+
const input = action.args['steps'];
|
|
117
|
+
if (!Array.isArray(input) || input.length < 1 || input.length > 64)
|
|
118
|
+
throw new Error('steps must contain between 1 and 64 items');
|
|
119
|
+
const steps = input.map(value => {
|
|
120
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
121
|
+
throw new Error('step must be an object');
|
|
122
|
+
const step = value;
|
|
123
|
+
if (Object.keys(step).some(key => !['kind', 'description', 'successCriteria', 'knowledgeUnitId'].includes(key)))
|
|
124
|
+
throw new Error('unknown step argument');
|
|
125
|
+
const kind = step['kind'];
|
|
126
|
+
if (kind !== 'LEARN' && kind !== 'PRACTICE' && kind !== 'CHECK' && kind !== 'REFLECT')
|
|
127
|
+
throw new Error('invalid step kind');
|
|
128
|
+
const description = step['description'], successCriteria = step['successCriteria'], knowledgeUnitId = step['knowledgeUnitId'];
|
|
129
|
+
for (const value of [description, successCriteria]) {
|
|
130
|
+
if (typeof value !== 'string' || !value.trim() || value.length > 10_000)
|
|
131
|
+
throw new Error('step description and successCriteria must contain 1 to 10000 characters');
|
|
132
|
+
}
|
|
133
|
+
if (knowledgeUnitId !== undefined && (typeof knowledgeUnitId !== 'string' || !knowledgeUnitId.trim()))
|
|
134
|
+
throw new Error('knowledgeUnitId must be non-empty');
|
|
135
|
+
return { kind, description: description, successCriteria: successCriteria, ...(typeof knowledgeUnitId === 'string' ? { knowledgeUnitId } : {}) };
|
|
136
|
+
});
|
|
137
|
+
return api.addMissionSteps(native, id, steps);
|
|
138
|
+
}
|
|
139
|
+
return method === 'finish_planning' ? api.finishMissionPlanning(native, id) : api.completeMission(native, id);
|
|
140
|
+
}
|
|
141
|
+
case 'get_activity': {
|
|
142
|
+
const id = action.args['activityId'];
|
|
143
|
+
if (typeof id !== 'string' || !id.trim())
|
|
144
|
+
throw new Error('activityId must be non-empty');
|
|
145
|
+
return api.getActivity(id, work.tenantId, context.project.id);
|
|
146
|
+
}
|
|
147
|
+
default: throw new Error('unsupported learning action');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=learning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning.js","sourceRoot":"","sources":["../../../../src/integrations/lingxiloop/learning.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,aAAa,EAAE,CAAC,YAAY,EAAE,eAAe,CAAC,EAAE,WAA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AAQ,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;gBACtK,CAAC,CAAC,CAAA;gBACF,OAAO,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,EAAE,KAAK,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,MAAM,KAAK,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QAC/G,CAAC;QACD,KAAK,cAAc,CAAC,CAAC,CAAC;YACpB,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YACpC,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;gBAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;YACzF,OAAO,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC/D,CAAC;QACD,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type HostAction, type WorkItem } from '../../protocol/types.js';
|
|
2
|
+
import { type SqlPool } from '../../control-plane/pg-store.js';
|
|
3
|
+
import type { LingxiLoopServices } from './service-contracts.js';
|
|
4
|
+
import type { SemanticMemory } from '../../memory/semantic.js';
|
|
5
|
+
export declare const MEMORY_METHODS: {
|
|
6
|
+
readonly list: readonly ["scope", "learnerId", "limit"];
|
|
7
|
+
readonly recall: readonly ["scope", "learnerId", "query", "limit"];
|
|
8
|
+
readonly note: readonly ["scope", "learnerId", "body", "kind", "validUntil"];
|
|
9
|
+
readonly verify: readonly ["scope", "learnerId", "id", "expectedVersion", "validUntil"];
|
|
10
|
+
readonly pin: readonly ["scope", "learnerId", "id", "expectedVersion", "pinned"];
|
|
11
|
+
readonly delete: readonly ["scope", "learnerId", "id", "expectedVersion"];
|
|
12
|
+
};
|
|
13
|
+
export declare function recallMemoryContext(work: Omit<WorkItem, 'leaseToken'>, services: Pick<LingxiLoopServices, 'permissionService'>, database: SqlPool, semantic?: SemanticMemory): Promise<import("../../memory/store.js").MemorySnapshot>;
|
|
14
|
+
export declare function executeMemory(work: Omit<WorkItem, 'leaseToken'>, action: HostAction, services: Pick<LingxiLoopServices, 'permissionService'>, database: SqlPool, semantic?: SemanticMemory): Promise<Record<string, unknown> | Record<string, unknown>[] | undefined>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { recallMemories, snapshotMemories } from '../../memory/store.js';
|
|
3
|
+
import { sessionKeyOf } from '../../protocol/types.js';
|
|
4
|
+
import { withTransaction } from '../../control-plane/pg-store.js';
|
|
5
|
+
export const MEMORY_METHODS = {
|
|
6
|
+
list: ['scope', 'learnerId', 'limit'], recall: ['scope', 'learnerId', 'query', 'limit'],
|
|
7
|
+
note: ['scope', 'learnerId', 'body', 'kind', 'validUntil'],
|
|
8
|
+
verify: ['scope', 'learnerId', 'id', 'expectedVersion', 'validUntil'],
|
|
9
|
+
pin: ['scope', 'learnerId', 'id', 'expectedVersion', 'pinned'],
|
|
10
|
+
delete: ['scope', 'learnerId', 'id', 'expectedVersion'],
|
|
11
|
+
};
|
|
12
|
+
export async function recallMemoryContext(work, services, database, semantic) {
|
|
13
|
+
if (!work.principalId)
|
|
14
|
+
throw new Error('missing memory recall principal');
|
|
15
|
+
await services.permissionService.assertCan({ actorUserId: work.principalId, companyId: work.tenantId,
|
|
16
|
+
action: 'agent_memory:read', resource: { type: 'conversation', id: work.sessionId } });
|
|
17
|
+
const { rows } = await database.query(`SELECT 1 FROM participants p JOIN im_channel_bindings b ON b.company_id=p.company_id
|
|
18
|
+
WHERE p.id=$1 AND p.company_id=$2 AND p.kind='human' AND p.departed_at IS NULL
|
|
19
|
+
AND b.channel_id=$3 AND b.profile->'members' ? p.id`, [work.principalId, work.tenantId, work.sessionId]);
|
|
20
|
+
const scopes = [
|
|
21
|
+
...(rows.length ? [{ tenantId: work.tenantId, scopeType: 'learner', scopeId: work.principalId }] : []),
|
|
22
|
+
{ tenantId: work.tenantId, scopeType: 'course', scopeId: work.sessionId },
|
|
23
|
+
{ tenantId: work.tenantId, scopeType: 'agent_role', scopeId: work.agentId },
|
|
24
|
+
];
|
|
25
|
+
if (!semantic)
|
|
26
|
+
return snapshotMemories(await Promise.all(scopes.map(async (scope) => ({ scope, items: await recallMemories(database, scope, '', 12) }))));
|
|
27
|
+
const saved = await database.query('SELECT request_snapshot FROM lingxios.agent_os_sessions WHERE session_key=$1', [sessionKeyOf(work)]);
|
|
28
|
+
const request = saved.rows[0]?.['request_snapshot'];
|
|
29
|
+
const query = (request?.workId === work.id ? `${request.revisions.at(-1)?.text ?? ''}\n${request.originalText}` : String(work.meta?.['text'] ?? '')).slice(0, 2000).replace(/[\uD800-\uDBFF]$/, '');
|
|
30
|
+
const groups = [];
|
|
31
|
+
for (const scope of scopes)
|
|
32
|
+
groups.push({ scope, items: await semantic.recall(work, scope, query, 12) });
|
|
33
|
+
return snapshotMemories(groups);
|
|
34
|
+
}
|
|
35
|
+
export async function executeMemory(work, action, services, database, semantic) {
|
|
36
|
+
const method = action.action.slice('memory.'.length);
|
|
37
|
+
if (!work.principalId || !action.action.startsWith('memory.') || !Object.hasOwn(MEMORY_METHODS, method))
|
|
38
|
+
throw new Error('unsupported memory action');
|
|
39
|
+
const allowed = MEMORY_METHODS[method];
|
|
40
|
+
if (Object.keys(action.args).some(key => !allowed.includes(key)))
|
|
41
|
+
throw new Error('unknown memory argument');
|
|
42
|
+
const scopeType = action.args['scope'] ?? 'course';
|
|
43
|
+
if (scopeType !== 'learner' && scopeType !== 'course' && scopeType !== 'agent_role')
|
|
44
|
+
throw new Error('invalid memory scope');
|
|
45
|
+
const learnerId = action.args['learnerId'];
|
|
46
|
+
if (scopeType !== 'learner' && learnerId !== undefined)
|
|
47
|
+
throw new Error('learnerId requires learner scope');
|
|
48
|
+
if (scopeType === 'learner' && (typeof learnerId !== 'string' || !learnerId.trim()))
|
|
49
|
+
throw new Error('learnerId is required');
|
|
50
|
+
const write = method !== 'list' && method !== 'recall';
|
|
51
|
+
await services.permissionService.assertCan({ actorUserId: work.principalId, companyId: work.tenantId,
|
|
52
|
+
action: write ? 'agent_memory:write' : 'agent_memory:read', resource: { type: 'conversation', id: work.sessionId } });
|
|
53
|
+
if (scopeType === 'learner') {
|
|
54
|
+
const { rows } = await database.query(`SELECT 1 FROM participants p JOIN im_channel_bindings b ON b.company_id=p.company_id
|
|
55
|
+
WHERE p.id=$1 AND p.company_id=$2 AND p.kind='human' AND p.departed_at IS NULL
|
|
56
|
+
AND b.channel_id=$3 AND b.profile->'members' ? p.id`, [learnerId, work.tenantId, work.sessionId]);
|
|
57
|
+
if (!rows.length)
|
|
58
|
+
throw new Error('learner is not an active human member of this conversation');
|
|
59
|
+
}
|
|
60
|
+
const scope = { tenantId: work.tenantId, scopeType: scopeType,
|
|
61
|
+
scopeId: scopeType === 'course' ? work.sessionId : scopeType === 'agent_role' ? work.agentId : learnerId };
|
|
62
|
+
if (!write) {
|
|
63
|
+
const query = action.args['query'] ?? '', limit = action.args['limit'] ?? 12;
|
|
64
|
+
if (typeof query !== 'string' || query.length > 2000 || !Number.isSafeInteger(limit) || Number(limit) < 1 || Number(limit) > 12)
|
|
65
|
+
throw new Error('invalid memory query or limit');
|
|
66
|
+
return semantic ? semantic.recall(work, scope, query, Number(limit)) : recallMemories(database, scope, query, Number(limit));
|
|
67
|
+
}
|
|
68
|
+
const validUntil = action.args['validUntil'];
|
|
69
|
+
if (validUntil !== undefined && (typeof validUntil !== 'string' || validUntil.length > 40
|
|
70
|
+
|| !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d{1,3})?(?:Z|[+-]\d\d:\d\d)$/.test(validUntil)
|
|
71
|
+
|| !Number.isFinite(Date.parse(validUntil)) || Date.parse(validUntil) <= Date.now()))
|
|
72
|
+
throw new Error('validUntil must be a future ISO timestamp');
|
|
73
|
+
return withTransaction(database, async (client) => {
|
|
74
|
+
const { rows } = await client.query(`SELECT s.request_snapshot FROM lingxios.agent_work_items w
|
|
75
|
+
JOIN lingxios.agent_os_sessions s ON s.session_key=$4
|
|
76
|
+
WHERE w.id=$1 AND w.fence=$2 AND w.status='leased' AND w.lease_expires_at>NOW() AND w.cancel_requested_at IS NULL
|
|
77
|
+
AND w.principal_id=$3 AND s.request_snapshot->>'workId'=w.id
|
|
78
|
+
AND jsonb_array_length(s.request_snapshot->'revisions')=jsonb_array_length(w.steer_inputs)
|
|
79
|
+
FOR UPDATE OF w`, [work.id, work.fence, work.principalId, sessionKeyOf(work)]);
|
|
80
|
+
const request = rows[0]?.['request_snapshot'];
|
|
81
|
+
if (!request)
|
|
82
|
+
throw new Error('memory write requires the current leased request');
|
|
83
|
+
const source = { workId: work.id, requestVersion: request.revisions.length + 1, sourceRef: request.sourceRef,
|
|
84
|
+
authorId: request.authorId, inputSha256: createHash('sha256').update(JSON.stringify({ originalText: request.originalText, revisions: request.revisions, attachments: request.attachments })).digest('hex') };
|
|
85
|
+
if (method === 'note') {
|
|
86
|
+
const body = action.args['body'], kind = action.args['kind'] ?? 'observation';
|
|
87
|
+
if (typeof body !== 'string' || !body.trim() || body.length > 2000
|
|
88
|
+
|| typeof kind !== 'string' || !/^[a-z_]{1,32}$/.test(kind))
|
|
89
|
+
throw new Error('invalid memory body or kind');
|
|
90
|
+
const id = `mem-${createHash('sha256').update(action.idempotencyKey).digest('hex')}`;
|
|
91
|
+
const saved = await client.query(`INSERT INTO lingxios.agent_memories
|
|
92
|
+
(tenant_id,id,scope_type,scope_id,body,kind,origin,source_refs,valid_until)
|
|
93
|
+
VALUES($1,$2,$3,$4,$5,$6,'explicit',$7::jsonb,$8::timestamptz)
|
|
94
|
+
ON CONFLICT(tenant_id,id) DO NOTHING RETURNING id,body,kind,origin,version,source_refs,valid_until`, [work.tenantId, id, scopeType, scope.scopeId, body.trim(), kind, JSON.stringify([source]), validUntil ?? null]);
|
|
95
|
+
if (!saved.rows.length)
|
|
96
|
+
throw new Error('memory note already exists; reconcile its original action receipt');
|
|
97
|
+
return saved.rows[0];
|
|
98
|
+
}
|
|
99
|
+
const id = action.args['id'], version = action.args['expectedVersion'];
|
|
100
|
+
if (typeof id !== 'string' || !id || !Number.isSafeInteger(version) || Number(version) < 1)
|
|
101
|
+
throw new Error('memory changes require id and expectedVersion');
|
|
102
|
+
if (method === 'delete') {
|
|
103
|
+
const deleted = await client.query(`DELETE FROM lingxios.agent_memories
|
|
104
|
+
WHERE tenant_id=$1 AND id=$2 AND scope_type=$3 AND scope_id=$4 AND version=$5 RETURNING id`, [work.tenantId, id, scopeType, scope.scopeId, version]);
|
|
105
|
+
if (!deleted.rows.length)
|
|
106
|
+
throw new Error('memory is unavailable or stale');
|
|
107
|
+
return { id, deleted: true };
|
|
108
|
+
}
|
|
109
|
+
if (method === 'pin') {
|
|
110
|
+
const pinned = action.args['pinned'];
|
|
111
|
+
if (typeof pinned !== 'boolean')
|
|
112
|
+
throw new Error('pinned must be a boolean');
|
|
113
|
+
const saved = await client.query(`UPDATE lingxios.agent_memories SET pinned=$6,version=version+1,
|
|
114
|
+
source_refs=source_refs||$7::jsonb,updated_at=NOW()
|
|
115
|
+
WHERE tenant_id=$1 AND id=$2 AND scope_type=$3 AND scope_id=$4 AND version=$5
|
|
116
|
+
AND jsonb_array_length(source_refs)<64
|
|
117
|
+
RETURNING id,body,kind,origin,pinned,version,source_refs,valid_until`, [work.tenantId, id, scopeType, scope.scopeId, version, pinned, JSON.stringify([source])]);
|
|
118
|
+
if (!saved.rows.length)
|
|
119
|
+
throw new Error('memory is unavailable, stale, or at its provenance limit');
|
|
120
|
+
return saved.rows[0];
|
|
121
|
+
}
|
|
122
|
+
const saved = await client.query(`UPDATE lingxios.agent_memories SET version=version+1,status='active',
|
|
123
|
+
valid_until=COALESCE($6::timestamptz,valid_until),source_refs=source_refs||$7::jsonb,updated_at=NOW()
|
|
124
|
+
WHERE tenant_id=$1 AND id=$2 AND scope_type=$3 AND scope_id=$4 AND version=$5 AND origin='explicit'
|
|
125
|
+
AND jsonb_array_length(source_refs)<64
|
|
126
|
+
AND (valid_until IS NULL OR valid_until>NOW() OR $6::timestamptz IS NOT NULL)
|
|
127
|
+
RETURNING id,body,kind,origin,version,source_refs,valid_until`, [work.tenantId, id, scopeType, scope.scopeId, version, validUntil ?? null, JSON.stringify([source])]);
|
|
128
|
+
if (!saved.rows.length)
|
|
129
|
+
throw new Error('memory is unavailable, stale, non-explicit, or at its provenance limit');
|
|
130
|
+
return saved.rows[0];
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../../src/integrations/lingxiloop/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAA0C,MAAM,uBAAuB,CAAA;AAChH,OAAO,EAAE,YAAY,EAAkC,MAAM,yBAAyB,CAAA;AACtF,OAAO,EAAE,eAAe,EAAgB,MAAM,iCAAiC,CAAA;AAK/E,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC;IACvF,IAAI,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC;IAC1D,MAAM,EAAE,CAAC,OAAO,EAAE,WAA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IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;YACzF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;gBAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAA;YACnG,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACtB,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC;;;;;oEAK+B,EAChE,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QACrG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAA;QACjH,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HostAction, WorkItem } from '../../protocol/types.js';
|
|
2
|
+
import type { LingxiLoopServices } from './service-contracts.js';
|
|
3
|
+
export declare const POLL_METHODS: {
|
|
4
|
+
readonly create: readonly ["question", "mode", "options", "expiresInMinutes"];
|
|
5
|
+
readonly vote: readonly ["messageId", "optionIds"];
|
|
6
|
+
readonly close: readonly ["messageId"];
|
|
7
|
+
readonly show: readonly ["messageId"];
|
|
8
|
+
};
|
|
9
|
+
export declare function executePoll(work: Omit<WorkItem, 'leaseToken'>, action: HostAction, services: Pick<LingxiLoopServices, 'pollApplication' | 'permissionService'>): Promise<unknown>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const POLL_METHODS = { create: ['question', 'mode', 'options', 'expiresInMinutes'], vote: ['messageId', 'optionIds'], close: ['messageId'], show: ['messageId'] };
|
|
2
|
+
export async function executePoll(work, action, services) {
|
|
3
|
+
const polls = services.pollApplication;
|
|
4
|
+
const method = action.action.slice('polls.'.length);
|
|
5
|
+
if (!polls || !work.principalId || !action.action.startsWith('polls.') || !Object.hasOwn(POLL_METHODS, method))
|
|
6
|
+
throw new Error('unsupported poll action or missing principal');
|
|
7
|
+
const allowed = POLL_METHODS[method];
|
|
8
|
+
const args = action.args;
|
|
9
|
+
if (Object.keys(args).some(key => !allowed.includes(key)))
|
|
10
|
+
throw new Error('unknown poll argument');
|
|
11
|
+
const scope = { companyId: work.tenantId, actorId: work.agentId };
|
|
12
|
+
const messageId = args['messageId'];
|
|
13
|
+
if (method !== 'create') {
|
|
14
|
+
if (typeof messageId !== 'string' || !messageId.trim())
|
|
15
|
+
throw new Error('messageId is required');
|
|
16
|
+
if (await polls.conversationId(work.tenantId, messageId) !== work.sessionId)
|
|
17
|
+
throw new Error('poll is outside the authorized conversation');
|
|
18
|
+
}
|
|
19
|
+
await services.permissionService.assertCan({ actorUserId: work.principalId, companyId: work.tenantId,
|
|
20
|
+
action: method === 'show' ? 'poll:read' : method === 'create' ? 'poll:create' : method === 'vote' ? 'poll:vote' : 'poll:close',
|
|
21
|
+
resource: method === 'create' ? { type: 'conversation', id: work.sessionId } : { type: 'poll', id: messageId },
|
|
22
|
+
});
|
|
23
|
+
if (method === 'create') {
|
|
24
|
+
if (typeof args['question'] !== 'string' || !args['question'].trim() || args['question'].length > 280)
|
|
25
|
+
throw new Error('invalid poll question');
|
|
26
|
+
const options = args['options'];
|
|
27
|
+
if (!Array.isArray(options) || options.length < 2 || options.length > 10 || options.some(value => typeof value !== 'string' || !value.trim() || value.length > 120))
|
|
28
|
+
throw new Error('invalid poll options');
|
|
29
|
+
const mode = args['mode'] ?? 'single';
|
|
30
|
+
if (mode !== 'single' && mode !== 'multi')
|
|
31
|
+
throw new Error('invalid poll mode');
|
|
32
|
+
const expires = args['expiresInMinutes'];
|
|
33
|
+
if (expires != null && (typeof expires !== 'number' || !Number.isFinite(expires) || expires <= 0))
|
|
34
|
+
throw new Error('invalid poll expiry');
|
|
35
|
+
return polls.create({ ...scope, conversationId: work.sessionId, question: args['question'], mode, options, expiresInMinutes: (expires ?? null), idempotencyKey: action.idempotencyKey });
|
|
36
|
+
}
|
|
37
|
+
if (method === 'vote') {
|
|
38
|
+
const optionIds = args['optionIds'];
|
|
39
|
+
if (!Array.isArray(optionIds) || optionIds.length > 10 || optionIds.some(value => typeof value !== 'string' || !value.trim()))
|
|
40
|
+
throw new Error('invalid vote options');
|
|
41
|
+
return polls.vote({ ...scope, messageId: messageId, voterKind: 'agent', optionIds });
|
|
42
|
+
}
|
|
43
|
+
if (method === 'close')
|
|
44
|
+
return polls.close({ ...scope, messageId: messageId, reason: 'manual' });
|
|
45
|
+
return polls.show(work.tenantId, messageId);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=polls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polls.js","sourceRoot":"","sources":["../../../../src/integrations/lingxiloop/polls.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,EAAW,CAAA;AAEjL,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAkC,EAAE,MAAkB,EAAE,QAA2E;IACnK,MAAM,KAAK,GAAG,QAAQ,CAAC,eAAe,CAAA;IACtC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACnD,IA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
+
import type { HostAction, WorkItem } from '../../protocol/types.js';
|
|
2
|
+
import type { LingxiLoopServices } from './service-contracts.js';
|
|
3
|
+
export declare const PRESENTATION_METHODS: {
|
|
4
|
+
readonly create: readonly ["requirements", "title", "sourceIds", "targetSlideCount", "language"];
|
|
5
|
+
readonly get: readonly ["presentationId"];
|
|
6
|
+
readonly cancel: readonly ["presentationId"];
|
|
7
|
+
readonly retry: readonly ["presentationId"];
|
|
8
|
+
readonly revise_outline: readonly ["presentationId", "expectedRevision", "feedback", "targetSlideCount"];
|
|
9
|
+
readonly revise: readonly ["presentationId", "instruction", "scope", "pageIds", "sectionIds"];
|
|
10
|
+
};
|
|
11
|
+
export declare function executePresentation(work: Omit<WorkItem, 'leaseToken'>, action: HostAction, services: LingxiLoopServices): Promise<unknown>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { nativeWork } from './actions.js';
|
|
2
|
+
export const PRESENTATION_METHODS = {
|
|
3
|
+
create: ['requirements', 'title', 'sourceIds', 'targetSlideCount', 'language'], get: ['presentationId'],
|
|
4
|
+
cancel: ['presentationId'], retry: ['presentationId'],
|
|
5
|
+
revise_outline: ['presentationId', 'expectedRevision', 'feedback', 'targetSlideCount'],
|
|
6
|
+
revise: ['presentationId', 'instruction', 'scope', 'pageIds', 'sectionIds'],
|
|
7
|
+
};
|
|
8
|
+
export async function executePresentation(work, action, services) {
|
|
9
|
+
const api = services.presentations;
|
|
10
|
+
const method = action.action.slice('presentations.'.length);
|
|
11
|
+
if (!api || !action.action.startsWith('presentations.') || !Object.hasOwn(PRESENTATION_METHODS, method))
|
|
12
|
+
throw new Error('unsupported or approval-required presentation action');
|
|
13
|
+
const allowed = PRESENTATION_METHODS[method];
|
|
14
|
+
if (Object.keys(action.args).some(key => !allowed.includes(key)))
|
|
15
|
+
throw new Error('unknown presentation argument');
|
|
16
|
+
const native = nativeWork(work);
|
|
17
|
+
await services.permissionService.assertCan({ actorUserId: native.authorizationUserId, companyId: native.companyId,
|
|
18
|
+
action: method === 'get' ? 'knowledge:read' : 'knowledge:write', resource: { type: 'conversation', id: native.channelId }, });
|
|
19
|
+
if (method === 'create')
|
|
20
|
+
return api.createPresentationForAgent(native, api.createPresentationRequestSchema.parse({ ...action.args, idempotencyKey: action.idempotencyKey }));
|
|
21
|
+
const { presentationId, ...args } = action.args;
|
|
22
|
+
if (typeof presentationId !== 'string' || !presentationId.trim())
|
|
23
|
+
throw new Error('presentationId is required');
|
|
24
|
+
const input = { ...args, idempotencyKey: action.idempotencyKey };
|
|
25
|
+
switch (method) {
|
|
26
|
+
case 'get': return api.getPresentationForAgent(native, presentationId);
|
|
27
|
+
case 'cancel': return api.cancelPresentationForAgent(native, presentationId, input);
|
|
28
|
+
case 'retry': return api.retryPresentationForAgent(native, presentationId, input);
|
|
29
|
+
case 'revise_outline': return api.revisePresentationOutlineForAgent(native, presentationId, api.revisePresentationOutlineRequestSchema.parse(input));
|
|
30
|
+
case 'revise': return api.revisePresentationForAgent(native, presentationId, api.revisePresentationRequestSchema.parse(input));
|
|
31
|
+
default: throw new Error('unsupported presentation action');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=presentations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentations.js","sourceRoot":"","sources":["../../../../src/integrations/lingxiloop/presentations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC;IACvG,MAAM,EAAE,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,gBAAgB,CAAC;IACrD,cAAc,EAAE,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,CAAC;IACtF,MAAM,E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Label?: string;
|
|
3
|
+
title: string;
|
|
4
|
+
items: {
|
|
5
|
+
input?: {
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
label: string;
|
|
8
|
+
};
|
|
9
|
+
multiple?: boolean;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
description?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
prompt: string;
|
|
14
|
+
choices: {
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
description?: string;
|
|
17
|
+
value: string;
|
|
18
|
+
label: string;
|
|
19
|
+
}[];
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function record(value, fields) {
|
|
2
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
3
|
+
throw new Error('questionnaire object required');
|
|
4
|
+
if (Object.keys(value).some(key => !fields.includes(key)))
|
|
5
|
+
throw new Error('unknown questionnaire field');
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
function text(value, max) {
|
|
9
|
+
if (typeof value !== 'string' || !value.trim() || value.length > max)
|
|
10
|
+
throw new Error(`questionnaire text must contain 1..${max} characters`);
|
|
11
|
+
return value.trim();
|
|
12
|
+
}
|
|
13
|
+
export function questionnaire(args) {
|
|
14
|
+
const title = args['title'] === undefined ? 'Agent 提问' : text(args['title'], 160);
|
|
15
|
+
const rawItems = args['items'];
|
|
16
|
+
if (!Array.isArray(rawItems) || rawItems.length < 1 || rawItems.length > 8)
|
|
17
|
+
throw new Error('items must contain 1..8 questions');
|
|
18
|
+
const names = new Set();
|
|
19
|
+
const items = rawItems.map((raw, index) => {
|
|
20
|
+
const item = record(raw, ['name', 'prompt', 'description', 'required', 'multiple', 'choices', 'input']);
|
|
21
|
+
for (const flag of ['required', 'multiple']) {
|
|
22
|
+
if (item[flag] !== undefined && typeof item[flag] !== 'boolean')
|
|
23
|
+
throw new Error(`${flag} must be boolean`);
|
|
24
|
+
}
|
|
25
|
+
const name = item['name'] === undefined ? `question_${index + 1}` : text(item['name'], 64);
|
|
26
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(name) || names.has(name))
|
|
27
|
+
throw new Error('question names must be unique identifiers');
|
|
28
|
+
names.add(name);
|
|
29
|
+
const rawChoices = item['choices'] ?? [];
|
|
30
|
+
if (!Array.isArray(rawChoices) || rawChoices.length > 12)
|
|
31
|
+
throw new Error('at most 12 choices per question');
|
|
32
|
+
const values = new Set();
|
|
33
|
+
const choices = rawChoices.map(raw => {
|
|
34
|
+
const choice = record(raw, ['value', 'label', 'description', 'disabled']);
|
|
35
|
+
if (choice['disabled'] !== undefined && typeof choice['disabled'] !== 'boolean')
|
|
36
|
+
throw new Error('disabled must be boolean');
|
|
37
|
+
const value = text(choice['value'], 120);
|
|
38
|
+
if (values.has(value))
|
|
39
|
+
throw new Error('duplicate choice value');
|
|
40
|
+
values.add(value);
|
|
41
|
+
return { value, label: text(choice['label'], 500),
|
|
42
|
+
...(choice['description'] === undefined ? {} : { description: text(choice['description'], 500) }),
|
|
43
|
+
...(choice['disabled'] === true ? { disabled: true } : {}),
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const input = item['input'] === undefined ? undefined : record(item['input'], ['label', 'placeholder']);
|
|
47
|
+
if (!choices.length && !input)
|
|
48
|
+
throw new Error('question requires choices or freeform input');
|
|
49
|
+
return { name, prompt: text(item['prompt'], 500), choices,
|
|
50
|
+
...(item['description'] === undefined ? {} : { description: text(item['description'], 1000) }),
|
|
51
|
+
...(item['required'] === true ? { required: true } : {}), ...(item['multiple'] === true ? { multiple: true } : {}),
|
|
52
|
+
...(input ? { input: { label: text(input['label'], 120), ...(input['placeholder'] === undefined ? {} : { placeholder: text(input['placeholder'], 160) }) } } : {}),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
return { title, items, ...(args['submitLabel'] === undefined ? {} : { submitLabel: text(args['submitLabel'], 80) }) };
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=questionnaire.js.map
|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@
|
|
|
1
|
+
import type { HostAction, WorkItem } from '../../protocol/types.js';
|
|
2
|
+
import type { LingxiLoopServices } from './service-contracts.js';
|
|
3
|
+
export declare const RESEARCH_METHODS: {
|
|
4
|
+
readonly search: readonly ["query", "limit"];
|
|
5
|
+
readonly read: readonly ["url"];
|
|
6
|
+
};
|
|
7
|
+
export declare function executeResearch(work: Omit<WorkItem, 'leaseToken'>, action: HostAction, services: Pick<LingxiLoopServices, 'permissionService'>): Promise<{
|
|
8
|
+
provider: "OpenAlex";
|
|
9
|
+
query: string;
|
|
10
|
+
results: import("../../research/index.js").ResearchSearchResult[];
|
|
11
|
+
} | {
|
|
12
|
+
url: string;
|
|
13
|
+
finalUrl: string;
|
|
14
|
+
contentType: string;
|
|
15
|
+
text: string;
|
|
16
|
+
bytes: number;
|
|
17
|
+
sha256: string;
|
|
18
|
+
truncated: boolean;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readResearch, searchResearch } from '../../research/index.js';
|
|
2
|
+
export const RESEARCH_METHODS = { search: ['query', 'limit'], read: ['url'] };
|
|
3
|
+
export async function executeResearch(work, action, services) {
|
|
4
|
+
const method = action.action.slice('research.'.length);
|
|
5
|
+
if (!work.principalId || !action.action.startsWith('research.') || !Object.hasOwn(RESEARCH_METHODS, method))
|
|
6
|
+
throw new Error('unsupported research action or missing principal');
|
|
7
|
+
const allowed = RESEARCH_METHODS[method];
|
|
8
|
+
if (Object.keys(action.args).some(key => !allowed.includes(key)))
|
|
9
|
+
throw new Error('unknown research argument');
|
|
10
|
+
await services.permissionService.assertCan({ actorUserId: work.principalId, companyId: work.tenantId, action: 'agent:read', resource: { type: 'conversation', id: work.sessionId } });
|
|
11
|
+
if (method === 'search') {
|
|
12
|
+
if (typeof action.args['query'] !== 'string' || (action.args['limit'] !== undefined && typeof action.args['limit'] !== 'number'))
|
|
13
|
+
throw new Error('invalid research search arguments');
|
|
14
|
+
return searchResearch(action.args['query'], action.args['limit']);
|
|
15
|
+
}
|
|
16
|
+
if (typeof action.args['url'] !== 'string')
|
|
17
|
+
throw new Error('research URL is required');
|
|
18
|
+
return readResearch(action.args['url']);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=research.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research.js","sourceRoot":"","sources":["../../../../src/integrations/lingxiloop/research.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAGtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAW,CAAA;AAEtF,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAkC,EAAE,MAAkB,EAAE,QAAuD;IACnJ,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACtD,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;IAChL,MAAM,OAAO,GAAsB,gBAAgB,CAAC,MAAuC,CAAC,CAAA;IAC5F,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAC9G,MAAM,QAAQ,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,MAA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