dsh-plugin-xujie-memory 0.5.0 → 0.7.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/ACCEPTANCE.md +37 -0
- package/BUILD-PROVENANCE.json +53 -0
- package/CHANGELOG.md +40 -1
- package/LICENSE +21 -21
- package/README.md +67 -17
- package/README_EN.md +54 -8
- package/cordis.patch.yml +49 -49
- package/lib/client.js +17219 -0
- package/lib/controller.js +307 -0
- package/lib/index.js +200 -14
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +15104 -0
- package/lib/typert.remote-client.d.ts +40 -0
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +15093 -0
- package/lib/types.d.ts +13 -0
- package/lib/types.js +1 -0
- package/package.json +49 -5
- package/python/specs/characters/aloof.json +14 -14
- package/python/specs/characters/gentle.json +14 -14
- package/python/specs/characters/tsundere.json +14 -14
- package/python/specs/debt.v1.json +31 -31
- package/python/specs/nickname.v1.json +16 -16
- package/python/specs/preference.v1.json +16 -16
- package/python/xujie_memory/__init__.py +123 -123
- package/python/xujie_memory/admission.py +211 -211
- package/python/xujie_memory/audit.py +377 -377
- package/python/xujie_memory/benchmark.py +281 -281
- package/python/xujie_memory/character.py +199 -199
- package/python/xujie_memory/console.py +41 -41
- package/python/xujie_memory/consolidate.py +356 -356
- package/python/xujie_memory/due.py +121 -121
- package/python/xujie_memory/emotion.py +573 -573
- package/python/xujie_memory/engine.py +1333 -1312
- package/python/xujie_memory/errors.py +98 -98
- package/python/xujie_memory/importance.py +104 -104
- package/python/xujie_memory/judge.py +350 -350
- package/python/xujie_memory/management.py +203 -0
- package/python/xujie_memory/memory.py +71 -10
- package/python/xujie_memory/orchestrator.py +690 -666
- package/python/xujie_memory/phrasing.py +292 -292
- package/python/xujie_memory/privacy.py +105 -0
- package/python/xujie_memory/schema.sql +492 -480
- package/python/xujie_memory/server.py +76 -0
- package/python/xujie_memory/specs.py +170 -170
- package/python/xujie_memory/summary.py +238 -238
- package/scripts/build.mjs +19 -0
- package/scripts/prepack.mjs +9 -0
- package/scripts/test-all.mjs +9 -0
- package/scripts/test-node.mjs +10 -0
- package/src/client/MemoryPanel.tsx +536 -0
- package/src/client/NeuralField.tsx +88 -0
- package/src/client/css.d.ts +4 -0
- package/src/client/icons.tsx +28 -0
- package/src/client/index.tsx +59 -0
- package/src/client/memory-adapter.ts +67 -0
- package/src/client/model.ts +79 -0
- package/src/client/neural/engine.ts +999 -0
- package/src/client/neural/morphology.ts +219 -0
- package/src/client/panel.css +337 -0
- package/src/client/types.ts +6 -0
- package/src/controller.ts +88 -0
- package/src/generated/typert.host.js +449 -0
- package/src/generated/typert.remote-client.js +438 -0
- package/src/index.ts +2 -0
- package/src/types.ts +13 -0
- package/test/cordis-fixture.mjs +5 -0
- package/test/management_regression.py +187 -0
- package/test/node-regression.entry.mjs +52 -0
- package/vendor/DSH-LICENSE.txt +21 -0
- package/vendor/THIRD-PARTY.md +6 -0
- package/vendor/dsh-protocol/index.ts +484 -0
- package/vendor/dsh-protocol/json-value.ts +53 -0
- package/vendor/dsh-protocol/owned-value.ts +39 -0
- package/vendor/dsh-protocol/principal.ts +17 -0
- package/vendor/dsh-protocol/remote-access.ts +38 -0
- package/vendor/dsh-protocol/remote-error.ts +49 -0
- package/vendor/dsh-protocol/remote-info.ts +161 -0
- package/vendor/dsh-protocol/types.ts +939 -0
- package/vendor/licenses/jridgewell-gen-mapping-MIT.txt +19 -0
- package/vendor/licenses/jridgewell-resolve-uri-MIT.txt +19 -0
- package/vendor/licenses/jridgewell-sourcemap-codec-MIT.txt +19 -0
- package/vendor/licenses/jridgewell-trace-mapping-MIT.txt +19 -0
- package/vendor/licenses/zod-MIT.txt +21 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/** Lazy assembly of generated Remote definitions using caller-supplied Zod; no runtime imports. */
|
|
2
|
+
|
|
3
|
+
import type { z } from 'zod'
|
|
4
|
+
import type {
|
|
5
|
+
InvocationDescriptor,
|
|
6
|
+
TypertClientRemote,
|
|
7
|
+
TypertRemoteCodecSpec,
|
|
8
|
+
TypertRemoteInfo,
|
|
9
|
+
TypertRemoteInputOptions,
|
|
10
|
+
TypertRemoteMethod,
|
|
11
|
+
TypertRemoteParameterSpec,
|
|
12
|
+
TypertRemoteSpec,
|
|
13
|
+
TypertRemoteValue,
|
|
14
|
+
} from './types.ts'
|
|
15
|
+
|
|
16
|
+
type Method = TypertRemoteMethod<object, unknown> | TypertRemoteMethod<object, unknown, 'stream', unknown>
|
|
17
|
+
type Parameter = TypertRemoteParameterSpec & { readonly wire: string }
|
|
18
|
+
type Index = Pick<TypertRemoteInfo, 'descriptors' | 'methods'>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Retain one generated definition per endpoint without constructing parsers or projections.
|
|
22
|
+
* The class instance builds its shared descriptor/method index on first access;
|
|
23
|
+
* input schemas and JSON Schema projections are cached only when requested.
|
|
24
|
+
* @param spec - compiler-produced method facts and Zod factories.
|
|
25
|
+
* @param zod - the generated artifact's Zod runtime for named-input parsers.
|
|
26
|
+
* @returns a lazy, mountable info instance with no registration or transport effects.
|
|
27
|
+
*/
|
|
28
|
+
export function createTypertRemoteInfo(spec: TypertRemoteSpec, zod: typeof z): TypertRemoteInfo {
|
|
29
|
+
return new RemoteInfo(spec, zod)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class RemoteInfo implements TypertRemoteInfo {
|
|
33
|
+
private index?: Index
|
|
34
|
+
|
|
35
|
+
constructor(private readonly spec: TypertRemoteSpec, private readonly zod: typeof z) {}
|
|
36
|
+
|
|
37
|
+
get package(): string { return this.spec.package }
|
|
38
|
+
get descriptors(): readonly InvocationDescriptor[] { return this.resolve().descriptors }
|
|
39
|
+
get methods(): TypertRemoteInfo['methods'] { return this.resolve().methods }
|
|
40
|
+
|
|
41
|
+
private resolve(): Index {
|
|
42
|
+
if (this.index !== undefined) return this.index
|
|
43
|
+
const zod = this.zod
|
|
44
|
+
const descriptors: InvocationDescriptor[] = []
|
|
45
|
+
const methods = Object.create(null) as Record<string, Method>
|
|
46
|
+
for (const [endpoint, definition] of Object.entries(this.spec.methods)) {
|
|
47
|
+
const separator = endpoint.indexOf('/')
|
|
48
|
+
const namespace = endpoint.slice(0, separator)
|
|
49
|
+
const method = endpoint.slice(separator + 1)
|
|
50
|
+
const parameters = definition.parameters.map(parameter => ({ ...parameter, wire: parameter.wire ?? parameter.name }))
|
|
51
|
+
const descriptor = {
|
|
52
|
+
...definition,
|
|
53
|
+
id: `${this.spec.package}#${endpoint}`,
|
|
54
|
+
namespace,
|
|
55
|
+
method,
|
|
56
|
+
parameters,
|
|
57
|
+
result: definition.result.description === undefined ? definition.result : new ResultValue(definition.result),
|
|
58
|
+
}
|
|
59
|
+
if (definition.invocation.kind === 'direct') {
|
|
60
|
+
const inputs: [NamedInput?, NamedInput?] = []
|
|
61
|
+
const direct = Object.assign(descriptor, {
|
|
62
|
+
input(options?: TypertRemoteInputOptions) {
|
|
63
|
+
const strict = options?.strict === true
|
|
64
|
+
return inputs[strict ? 1 : 0] ??= new NamedInput(parameters, strict, zod)
|
|
65
|
+
},
|
|
66
|
+
invoke(remote: TypertClientRemote, input: object, signal?: AbortSignal) {
|
|
67
|
+
const named = input as Readonly<Record<string, unknown>>
|
|
68
|
+
const values = parameters.map(parameter => named[parameter.wire])
|
|
69
|
+
if (definition.cancellation !== undefined) values.push(signal)
|
|
70
|
+
// Namespace access retains the Gateway's mount checks and scoped receiver policy.
|
|
71
|
+
const receiver = Reflect.get(remote, namespace) as object
|
|
72
|
+
const call = Reflect.get(receiver, method) as (...args: unknown[]) => ReturnType<Method['invoke']>
|
|
73
|
+
return call.apply(receiver, values)
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
// The generated namespace return type is selected by this same descriptor's mode.
|
|
77
|
+
methods[endpoint] = direct as Method
|
|
78
|
+
}
|
|
79
|
+
descriptors.push(descriptor)
|
|
80
|
+
}
|
|
81
|
+
return this.index = { descriptors, methods }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Narrow a Registry descriptor to its generated direct-method capabilities.
|
|
87
|
+
* @param descriptor - a live descriptor, including possible source fallback or Context-only receivers.
|
|
88
|
+
* @returns whether generated named input and direct invocation are available.
|
|
89
|
+
*/
|
|
90
|
+
export function isTypertRemoteMethod(descriptor: InvocationDescriptor): descriptor is Method {
|
|
91
|
+
return descriptor.invocation.kind === 'direct' && descriptor.result.mode === 'strict'
|
|
92
|
+
&& 'input' in descriptor && typeof descriptor.input === 'function'
|
|
93
|
+
&& 'invoke' in descriptor && typeof descriptor.invoke === 'function'
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function optional(parameter: Parameter): boolean {
|
|
97
|
+
return parameter.source === 'json' && parameter.acceptsUndefined === true
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class NamedInput implements TypertRemoteValue<object> {
|
|
101
|
+
private schema?: z.ZodType<object>
|
|
102
|
+
private projection?: Pick<TypertRemoteValue, 'jsonSchema' | 'jsonSchemaError'>
|
|
103
|
+
|
|
104
|
+
constructor(
|
|
105
|
+
private readonly parameters: readonly Parameter[],
|
|
106
|
+
private readonly strict: boolean,
|
|
107
|
+
private readonly zod: typeof z,
|
|
108
|
+
) {}
|
|
109
|
+
|
|
110
|
+
private codec(parameter: Parameter): TypertRemoteCodecSpec {
|
|
111
|
+
return this.strict ? parameter.strictCodec : parameter.codec
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
readonly create = (): z.ZodType<object> => this.schema ??= this.zod.strictObject(Object.fromEntries(this.parameters.map((parameter) => {
|
|
115
|
+
const value = this.codec(parameter).create()
|
|
116
|
+
return [parameter.wire, optional(parameter) ? value.optional() : value.nonoptional()]
|
|
117
|
+
})))
|
|
118
|
+
|
|
119
|
+
get jsonSchema(): TypertRemoteValue['jsonSchema'] { return this.project().jsonSchema }
|
|
120
|
+
get jsonSchemaError(): string | undefined { return this.project().jsonSchemaError }
|
|
121
|
+
|
|
122
|
+
private project(): NonNullable<NamedInput['projection']> {
|
|
123
|
+
if (this.projection !== undefined) return this.projection
|
|
124
|
+
const unavailable = this.parameters.find(parameter => this.codec(parameter).jsonSchema === undefined)
|
|
125
|
+
if (unavailable !== undefined) {
|
|
126
|
+
return this.projection = { jsonSchemaError: this.codec(unavailable).jsonSchemaError ?? `No JSON Schema for parameter ${unavailable.wire}` }
|
|
127
|
+
}
|
|
128
|
+
return this.projection = {
|
|
129
|
+
jsonSchema: {
|
|
130
|
+
type: 'object',
|
|
131
|
+
properties: Object.fromEntries(this.parameters.map(parameter => [parameter.wire, {
|
|
132
|
+
...this.codec(parameter).jsonSchema,
|
|
133
|
+
...(parameter.description === undefined ? {} : { description: parameter.description }),
|
|
134
|
+
}])),
|
|
135
|
+
required: this.parameters.filter(parameter => !optional(parameter)).map(parameter => parameter.wire),
|
|
136
|
+
additionalProperties: false,
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
class ResultValue implements TypertRemoteCodecSpec {
|
|
143
|
+
private projection?: { readonly value: TypertRemoteValue['jsonSchema'] }
|
|
144
|
+
|
|
145
|
+
constructor(private readonly spec: TypertRemoteCodecSpec) {}
|
|
146
|
+
|
|
147
|
+
get mode(): 'strict' { return this.spec.mode }
|
|
148
|
+
get typeSymbol(): string { return this.spec.typeSymbol }
|
|
149
|
+
get create(): TypertRemoteCodecSpec['create'] { return this.spec.create }
|
|
150
|
+
get decode(): TypertRemoteCodecSpec['decode'] { return this.spec.decode }
|
|
151
|
+
get encode(): TypertRemoteCodecSpec['encode'] { return this.spec.encode }
|
|
152
|
+
get description(): string | undefined { return this.spec.description }
|
|
153
|
+
get jsonSchemaError(): string | undefined { return this.spec.jsonSchemaError }
|
|
154
|
+
get jsonSchema(): TypertRemoteValue['jsonSchema'] {
|
|
155
|
+
if (this.projection === undefined) {
|
|
156
|
+
const schema = this.spec.jsonSchema
|
|
157
|
+
this.projection = { value: schema === undefined ? undefined : { ...schema, description: this.spec.description } }
|
|
158
|
+
}
|
|
159
|
+
return this.projection.value
|
|
160
|
+
}
|
|
161
|
+
}
|